不推荐使用AuthorizationExecuteWithPrivileges [英] AuthorizationExecuteWithPrivileges is deprecated

查看:99
本文介绍了不推荐使用AuthorizationExecuteWithPrivileges的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从更新到OSX 10.7 Lion以来,Xcode告诉我AuthorizationExecuteWithPrivileges已弃用.

Since updating to OSX 10.7 Lion, Xcode tells me that AuthorizationExecuteWithPrivileges is deprecated.

有人可以建议我的应用程序可以写入没有权限的目录的方法吗?

Can anyone suggest a way my application can write to a directory it doesn't have permission for?

推荐答案

实际上,AuthorizationExecuteWithPrivileges()已被弃用很长时间了,直到最近,头文件才赶上了这个事实.

In fact, AuthorizationExecuteWithPrivileges() has been deprecated for a very long time, it's only recently that the header file has caught up with this fact.

您可以在应用程序中创建特权帮助器工具.您可以使用ServiceManagement.frameworkSMJobBless()函数将帮助程序部署到系统launchd上下文中:然后,当您需要执行特权任务时,只需向特权帮助程序发送消息即可完成这项工作.

You can create a privileged helper tool as part of your application. You can use ServiceManagement.framework's SMJobBless() function to have the helper deployed into the system launchd context: then when you need to perform privileged tasks, you just message the privileged helper to do that work.

有一些隐藏的复杂性,因为应用程序和帮助程序必须在SMJobBless()认为它们应该一起使用之前声明彼此的签名身份,并且您需要让链接器编写帮助程序工具的Info.plist文件放入二进制文件中. Apple的文档和Apple提供了示例项目,也是.

There's a little bit of hidden complexity, in that the app and the helper must each declare the signing identity of the other before SMJobBless() believes they're supposed to be used together, and you need to get the linker to write the helper tool's Info.plist file into the binary. That's all covered by Apple's Documentation and Apple have provided a sample project, too.

编写了一个示例应用程序,该应用程序使用SMJobBless()来部署其特权助手.

I wrote an example application that uses SMJobBless() to deploy its privileged helper.

这篇关于不推荐使用AuthorizationExecuteWithPrivileges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆