我以 root 用户身份创建了一个应用程序,它运行良好(在 root 用户中)。当我与标准用户尝试相同的应用程序时,它没有解决。然后我知道我需要 root 权限才能运行应用程序。我谷歌了几天,但没有得到它。我已经阅读了一些问题和苹果文档。哪个是-
但我仍然没有得到任何东西。我要知道的另一件事是我需要创建一个新项目才能获得 root 权限,对吗?任何你能告诉我的对我有帮助的都请去做。每一个建议都是最受欢迎的。
现在我正在尝试这个-
- (BOOL) runProcessAsAdministrator:(NSString*)scriptPath
withArguments:(NSArray *)arguments
output:(NSString **)output
errorDescription:(NSString **)errorDescription {
NSString * allArgs = [arguments componentsJoinedByString:@" "];
NSString * fullScript = [NSString stringWithFormat:@"'%@' %@", scriptPath, allArgs];
NSDictionary *errorInfo = [NSDictionary new];
NSString *script = [NSString stringWithFormat:@"do shell script \"%@\" with administrator privileges", fullScript];
NSAppleScript *appleScript = [[NSAppleScript new] initWithSource:script];
NSAppleEventDescriptor * eventResult = [appleScript executeAndReturnError:&errorInfo];
// Check errorInfo
if (! eventResult)
{ …Run Code Online (Sandbox Code Playgroud)