Hi All,
I have a finder sync extension that passes data back to my main app. It currently writes to a plist file in my group container folder. Since updating to macOS 15, I have been getting this pop-up every time I trigger this writing to the plist after the finder sync extension loads.
This is how I write to the plist from my finder sync extension:
let appGroupDefaults = UserDefaults(suiteName: "group.team_id.Finder-Sync-Extension-Test-Project")
let items = FIFinderSyncController.default().selectedItemURLs()
DispatchQueue.main.async {
let url = items?.first?.absoluteString
var file = items?.first?.lastPathComponent
if let defaults = appGroupDefaults{
defaults.set(url, forKey: "targetURL")
defaults.synchronize()
}
self.showWindow(with: NSExtensionContext())
}
This is how I read the plist from my main app:
if let defaults = UserDefaults(suiteName: "group.team_id.Finder-Sync-Extension-Test-Project") {
defaults.synchronize()
if let clickedUrl = defaults.string(forKey: "targetURL") {
window = NSWindow(contentRect: NSScreen.main?.frame ?? .zero,
styleMask: [.miniaturizable, .closable, .resizable, .titled],
backing: .buffered,
defer: false)
window?.title = "My App"
window?.makeKeyAndOrderFront(nil)
textField.stringValue = clickedUrl
window?.contentView?.addSubview(textField)
}
}
It is fine if this popup happens once and the user's choice gets remembered. I just don't want it to happen every time.
Any help on if this is the correct way to pass data between the finder sync extension and the main app or on how to get macOS to remember the choice of the user would be great.
Thanks, James
I have a finder sync extension that passes data back to my main app. It currently writes to a plist file in my group container folder.
Just to be clear, that code is writing to a shared preference file, NOT a file in group container (more on that later...).
Since updating to macOS 15, I have been getting this pop-up every time I trigger this writing to the plist after the finder sync extension loads.
Looking at your code, I don't think this is actually the right group ID:
let appGroupDefaults = UserDefaults(suiteName: "group.team_id.Finder-Sync-Extension-Test-Project")
From Create App Groups for macOS apps:
App Groups on macOS differ from other Apple platforms. Not using provisioning profiles means App Group names are not guaranteed to be unique. Instead, a macOS App Group uses your team’s identifier as a prefix for its name to provide that uniqueness. This also means you manage macOS App Groups locally, rather than using a centralized database like the developer portal. To create an App Group for a macOS app, follow these...
The other recommendation I have here is to verify the group ID by calling containerURL(forSecurityApplicationGroupIdentifier:) and passing in the same identifier. The issue here is that the complicated history of init(suiteName:) means that it's returning a valid object to "someone else's" preference instead of failing. containerURL(forSecurityApplicationGroupIdentifier:) doesn't have that issue, so it should just fail if you're using the wrong ID.
Once you've confirmed the group ID with containerURL(forSecurityApplicationGroupIdentifier:), then that same ID should work fine with NSUserDefaults. If it doesn't, then please file a bug and post the bug number back here.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware