AuthorizationExecuteWithPrivileges 已弃用 [英] AuthorizationExecuteWithPrivileges is deprecated

查看:64
本文介绍了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?

推荐答案

我知道这听起来很疯狂,但这确实有效:

I know it sounds crazy, but this actually works:

NSDictionary *error = [NSDictionary new]; 
NSString *script =  @"do shell script "whoami > /tmp/me" with administrator privileges";  
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script]; 
if ([appleScript executeAndReturnError:&error]) {
  NSLog(@"success!"); 
} else {
  NSLog(@"failure!"); 
}

我正在从目标 C 执行 Applescript.唯一的缺点是您无法获得永久的 root 权限.每次运行时它都会要求输入密码.

I'm executing an Applescript from Objective C. The only disadvantage is that you cannot gain permanent root privileges with this. It will ask for the password each time you run this.

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

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