沙盒 Mac 应用程序是否可以写入全局默认域?

Is it possible for a sandboxed Mac app to write to the global defaults domain?

有什么方法可以让沙盒 Mac 应用读取 将密钥写入全局用户默认域 (NSGlobalDomain/.globalDomain)?现在,写入失败,此错误正在控制台中记录。

[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

虽然 Mac App Store 合规性不是问题,但我希望将应用程序保留在沙盒中。

我可以通过将以下内容添加到应用程序的权利文件来解决问题。

<key>com.apple.security.temporary-exception.shared-preference.read-write</key>
<string>kCFPreferencesAnyApplication</string>

See here for the docs on this entitlements key