What entitlements must I specify to use defaults write com.apple.screencapture in NSTask()

你离开我真会死。 提交于 2020-01-15 07:20:09

问题


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.



来源:https://stackoverflow.com/questions/30016476/what-entitlements-must-i-specify-to-use-defaults-write-com-apple-screencapture-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!