What entitlements must I specify to use defaults w

2019-07-19 08:29发布

问题:

I got the app working fine then went to submit to the app store and discovered this thing called the sandbox :-p

I have been reading the documentation and developer forums, but I cant figure out specifically what entitlement I need to add to get this working:

let task = NSTask()
    task.launchPath = "/bin/bash"
    task.arguments = ["-c",
        "defaults write com.apple.screencapture type gif;killall SystemUIServer"]
    task.launch()

I've thought perhaps com.apple.screencapture and com.apple.security.temporary-exception.shared-preference.read-write as BOOLEAN YES might do the trick, but unfortunately not

回答1:

Do it without NSTask and without the shell:

For defaults write use com.apple.security.temporary-exception.shared-preference.read-write and add the domain you'd like to modify (eg. com.apple.screencapture) and then use CFPreferencesSetValue()

For killall use com.apple.security.temporary-exception.apple-events and run an Applescript / send AppleEvents to terminate specific processes.

As you see, both entitlements are temporary and you need good reasons to get them pass the review. Goal of sandbox is that apps don't interfere with other apps. Especially terminating SystemUIServer can be very intrusive.