Everything is OK in previous macOS versions.
But today when I call try agent.register(). I got an error: - Error Domain=SMAppServiceErrorDomain Code=1 "Operation not permitted" UserInfo={NSLocalizedFailureReason=Operation not permitted} #0
The agent is init with SMAppService.agent(plistName: ...)
And I took a look for log:
2023-12-21 01:03:20.398350+0800 0x17e07 Error 0x72960 8028 0 smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] getEffectiveDisposition: error: Error Domain=BTMErrorDomain Code=-95 "record not found" UserInfo={NSLocalizedDescription=record not found}
2023-12-21 01:03:20.398386+0800 0x17e07 Error 0x0 8028 0 smd: [com.apple.xpc.smd:SMAppService] Unable to get disposition of item: <private> error: Error Domain=NSPOSIXErrorDomain Code=3
2023-12-21 01:03:20.398407+0800 0x17e07 Default 0x0 8028 0 smd: [com.apple.xpc.smd:all] Found status: 3 for <private>
2023-12-21 01:03:46.833936+0800 0x17bcc Default 0x72949 8028 0 smd: [com.apple.xpc.smd:SMAppServiceFactory] Setting up BundleProgram keys for <private>
2023-12-21 01:03:46.833986+0800 0x17bcc Default 0x72949 8028 0 smd: [com.apple.xpc.smd:SMAppServiceFactory] Setting up BundleProgram keys for <private>
2023-12-21 01:03:46.836622+0800 0x17e05 Default 0x72949 8029 0 backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] registerLaunchItem: pid=8236, uid=501, type=agent, parentURL=<private>, url=<private>, config=<private>
2023-12-21 01:03:46.839123+0800 0x17e05 Debug 0x72949 8029 0 backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] BTMStore: save scheduled.
2023-12-21 01:03:46.839164+0800 0x17e05 Debug 0x72949 8029 0 backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] RecordSet notification scheduled for uid -2
2023-12-21 01:03:46.903417+0800 0x17bcc Error 0x72949 8028 0 smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] -[BTMManager registerLaunchItemWithAuditToken:type:relativeURL:configuration:uid:]_block_invoke: error: sandbox required
2023-12-21 01:03:46.903449+0800 0x17bcc Error 0x72949 8028 0 smd: [com.apple.xpc.smd:SMAppService] Register of <private> rejected by BTM.
Btw, my app is a sandboxed App.
Post
Replies
Boosts
Views
Activity
Hello TextKit 2 development team,
I am trying to render a paragraph of text with different styles for specific words. I have carefully reviewed the sample code provided in the documentation but I couldn't find any method to display NSTextLayoutFragment with different styles in a single NSTextParagraph.
Currently, I am using
NSTextContentStorageDelegate.textContentStorage(:textParagraphWith:)
to output the corresponding NSTextParagraph, and then using
NSTextLayoutManagerDelegate.textLayoutManager(:textLayoutFragmentFor:in:)
to output the corresponding TextLayoutFragment. However, this only allows me to customize the style on a paragraph, while what I need is to customize the style of certain words within the paragraph.
I have guessed that I can achieve this by specifying NSTextLineFragment properties, but in reality, it does not display any content. Can you please guide me on how to accomplish this task?
Here are the sample codes:
import SwiftUI
struct Item: Identifiable, Hashable {
var id = UUID()
var text: String
}
struct Player: Identifiable {
var id = UUID()
var score: String
}
struct TestView: View {
@State var sidebarItems: [Item] = [
.init(text: "1"),
.init(text: "2")
]
@State var players: [Player] = [
.init(score: "2"),
.init(score: "3"),
.init(score: "6"),
.init(score: "1")]
@State private var selectedItem: Item?
var body: some View {
NavigationSplitView(columnVisibility: .constant(.all)) {
List(sidebarItems, selection: $selectedItem) { item in
Text(item.text)
}
Button("shuffle") {
withAnimation(.easeIn) {
players.shuffle()
sidebarItems.shuffle()
}
}
} content: {
List {
ForEach(players) { player in
Text(player.score)
}
}
} detail: {
Text("Detail")
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
But as a result. Animation working fine on content but not on sidebar
What is best practice for wrapping AVPlayerView in SwiftUI?
I want to wrap AVPlayerView into SwiftUI. Here are my codes(playground):
import PlaygroundSupport
import SwiftUI
import AVKit
class RecorderPlayerModel: ObservableObject {
@Published var playerView: AVPlayerView
init() {
self.playerView = AVPlayerView()
self.playerView.player = AVPlayer()
}
func reload(url: URL) {
let asset = AVAsset(url: url)
let item = AVPlayerItem(asset: asset)
self.playerView.player?.replaceCurrentItem(with: item)
}
}
struct RecorderPlayerView: NSViewRepresentable {
typealias NSViewType = AVPlayerView
var playerView: AVPlayerView
func makeNSView(context: Context) -> AVPlayerView {
return playerView
}
func updateNSView(_ nsView: AVPlayerView, context: Context) {}
}
struct ContentView: View {
@StateObject var playerViewModel: RecorderPlayerModel = .init()
var body: some View {
VStack {
RecorderPlayerView(playerView: playerViewModel.playerView)
.clipShape(RoundedRectangle(cornerRadius: 8))
.onAppear {
let fileManager = FileManager.default
if let url = URL(string: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerMeltdowns.mp4") {
Task {
do {
let (data, _) = try await URLSession.shared.data(from: url)
let fileUrl = fileManager.temporaryDirectory.appendingPathComponent("sample")
.appendingPathExtension(for: .mpeg4Movie)
try? fileManager.removeItem(at: fileUrl)
fileManager.createFile(atPath: fileUrl.path, contents: data)
playerViewModel.reload(url: fileUrl)
} catch {
print(error)
}
}
}
}
Button {
if playerViewModel.playerView.canBeginTrimming {
Task {
await playerViewModel.playerView.beginTrimming()
}
}
} label: {
Text("trim")
}
}.frame(width: 500, height: 500, alignment: .center)
}
}
PlaygroundPage.current.setLiveView(ContentView())
Since I want to trim the video, I cannot directly use VideoPlayer. But after wrapping AVPlayerView to NSViewRepresentable View, the trim view always lose interactivity.
Reproduce way: just double click at anywhere when trimming.
stackoverflow link
Bellows are the codes in Swift Playground.
import PlaygroundSupport
import SwiftUI
struct VisualEffectView: NSViewRepresentable
{
let material: NSVisualEffectView.Material = .contentBackground
let blendingMode: NSVisualEffectView.BlendingMode = .withinWindow
func makeNSView(context: Context) -> NSVisualEffectView
{
let visualEffectView = NSVisualEffectView()
visualEffectView.material = material
visualEffectView.blendingMode = blendingMode
visualEffectView.state = NSVisualEffectView.State.active
return visualEffectView
}
func updateNSView(_ visualEffectView: NSVisualEffectView, context: Context)
{
visualEffectView.material = material
visualEffectView.blendingMode = blendingMode
}
}
struct ContentView: View {
var body: some View {
ZStack {
Image(nsImage: #imageLiteral(resourceName: "background.jpg"))
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 400, height: nil, alignment: .center)
VisualEffectView()
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
The codes result in white area with the Image invisible.
I want to detect Settings Scene's on disappear/close event.
But when I watch scenePhase of Settings, nothing is printed.
@main
struct MyApp: App {
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
#if os(macOS)
Settings {
SettingsView()
}
.onChange(of: scenePhase) { newValue in
print(newValue)
}
#endif
}
}
Also ask on stackoverflow
I would like to call
navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then(() => {...});
in my background.js.
But It will neither resolve nor reject.
I try to run it in console of background.js, but only get
Promise {status: "pending"} = $1