Edit system preferences from cocoa

安稳与你 提交于 2019-12-12 10:10:45

问题


Is there any way to edit system preferences programmatically using cocoa? Is there some framework required? I need to do this to change the global proxy settings. Also, my app is sandboxed. Is there any sample code on how to do this? Thanks for your help.


回答1:


You're looking for the System Configuration framework, but it's not going to be easy. I don't think it's possible for a sandboxed app, because it requires root privilege. (Just like you have to authenticate as an admin to modify settings in the Network pane of System Preferences.) See the System Configuration Programming Guidelines. Among other things, they say:

Applications that need to create or duplicate sets, or activate or deactivate services have a more complicated task. They must use the low-level configuration APIs. In addition, to develop these applications you must understand and use the System Configuration schema to interpret and build dictionaries that describe the new sets and services.

It’s also important to realize that to modify network preferences (in other words, to change the persistent store), your application must acquire root privileges. This is not a trivial task; for more information, you can read Authorization Services Programming Guide and review the code samples AuthSample and MoreAuthSample available at http://developer.apple.com/samplecode/Security/idxAuthorization-date.html.

Currently, the low-level configuration APIs are very basic and somewhat difficult to use. In fact, to perform common operations, such as creating a new set, you must combine the System Configuration APIs with I/O Kit access. In future versions of Mac OS X, the System Configuration framework may provide higher-level APIs to perform such network-configuration tasks.

It goes on to recommend the MoreSCF sample code, but it's been relegated to the legacy documentation section.



来源:https://stackoverflow.com/questions/10760748/edit-system-preferences-from-cocoa

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