我正在开发一个简单的应用程序,可以让您快速输入要运行的shell命令。 它的功能很完美,但是有sudo命令的问题。 目前,它会检测sudo命令,然后我尝试让它弹出一个授权窗口,要求用户输入密码,就像在Installer中看到的那样。
以下是一旦检测到sudo命令后的代码:
SFAuthorization *authorization = [[SFAuthorization alloc] initWithFlags:kAuthorizationFlagPreAuthorize rights:NULL environment:kAuthorizationEmptyEnvironment];
if ([authorization obtainWithRight:"com.mycompany.myapplication" flags:kAuthorizationFlagPreAuthorize error:nil]){
//authorized, now run the command using NSTask.
}else{
//fail
}
据我所知,这是完全错误的。这只是我从文档中拼凑出来的东西。有任何想法吗?