Hello, I am trying to use app groups to share preferences between an app and its QuickLook extension (both sandboxed), but I can't understand why it's not working.
For testing, I created an empty macOS app project and added a QuickLook Extension, then on both the targets' entitlement files I added the app group domain in the form "teamid.test". Last but not least, in the Info.plist file of the QL extension i added some UTIs to have the QL extension called when previewing.
In the QL extension's PreviewViewController.swift file I try to save a value like this:
func preparePreviewOfFile(at url: URL, completionHandler handler: @escaping (Error?) -> Void) {
let defaults=UserDefaults(suiteName: "teamid.***")
defaults?.set(1, forKey: "test")
handler(nil)
}
If I try to run the app and preview a file though, I get this message in the Console:
Couldn't write values for keys ( test ) in CFPrefsPlistSource<0x7fb63681cce0> (Domain: teamid.***, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
And the value is not saved. The only way to make this work is to add a temporary exception in the extension target, like this:
<array>
<string>/Library/Group Containers/teamid.***/</string>
</array>
</plist>
What bugs me is that if I try to save a value from the app instead, it works.
Are app groups not supported for QuickLook extensions?
Thank you, Michele