Is there any way to allow a sandboxed Mac app to read and write keys to the global user defaults domain (NSGlobalDomain
/.globalDomain
)? Right now, the writes are failing and this error is being logged in the console.
[User Defaults] Couldn't write values for keys (...) in CFPrefsPlistSource<0x600002df5300> (Domain: kCFPreferencesAnyApplication, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
I'd like the keep the app sandboxed, though Mac App Store compliance isn't a concern.
I was able to solve the problem by adding the following to the app's entitlements file.
<key>com.apple.security.temporary-exception.shared-preference.read-write</key>
<string>kCFPreferencesAnyApplication</string>