C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – 在沙盒OSX应用程序中询问用户管理员密码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在编写一个应用程序,我希望自定义首选项窗口在允许任何更改之前要求输入管理员密码(但从不存储它). up unitl现在我一直在使用这段代码
OSStatus status;
    AuthorizationRef authorizationRef;

    // AuthorizationCreate and pass NULL as the initial
    // AuthorizationRights set so that the AuthorizationRef gets created
    // successfully,and then later call AuthorizationCopyRights to
    // determine or extend the allowable rights.
    // http://developer.apple.com/qa/qa2001/qa1172.html
    status = AuthorizationCreate(NULL,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,&authorizationRef);
    if (status != errAuthorizationSuccess)
    {
        NSLog(@"Error Creating Initial Authorization: %d",status);
        return status;
    }

    // kAuthorizationRightExecute == "system.privilege.admin"
    AuthorizationItem right = {kAuthorizationRightExecute,NULL,0};
    AuthorizationRights rights = {1,&right};
    AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;

    // Call AuthorizationCopyRights to determine or extend the allowable rights.
    status = AuthorizationCopyRights(authorizationRef,&rights,flags,NULL);
    if (status != errAuthorizationSuccess)
    {
        NSLog(@"Copy Rights Unsuccessful: %d",status);
    }
    return status;
@H_404_4@哪个工作正常,提出一个标准的os密码对话框,要求输入管理员密码.根据返回的状态启用/禁用首选项的nib中的各种控件.但是,现在我正在尝试使用SandBox应用程序,此代码始终返回errAuthorizationDenied.我已经查看了AuthorizationCopyRights和AuthorizationCreate的doc,但我看不到在SandBoxed环境中使用它们的参考.

@H_404_4@我尝试过各种各样的AuthorizationFlags标志,但它总是一样的结果.有没有办法修改上面的代码在沙盒中工作,或者这些天是否要求管理员密码?

解决方法

我查看了沙盒文档,Determine Whether Your App is Suitable for Sandboxing部分立即回答了您的问题. @H_404_4@来自文档

@H_404_4@游戏结束.

@H_404_4@事实上,我不确定你希望实现什么.为什么不让用户为应用程序确定自己的自定义首选项?

大佬总结

以上是大佬教程为你收集整理的objective-c – 在沙盒OSX应用程序中询问用户管理员密码全部内容,希望文章能够帮你解决objective-c – 在沙盒OSX应用程序中询问用户管理员密码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: