gpt4 book ai didi

macos - SMJobBless - 有关何时要求管理员密码的文档

转载 作者:行者123 更新时间:2023-12-03 16:08:29 25 4
gpt4 key购买 nike

我似乎找不到任何相关文档,所以希望有人可以确认我在 Apple 样本 SMJobBless 中看到的行为。代码。

我的印象是,如果它检测到需要安装新版本的帮助工具,它只会要求输入管理员密码。

但是,这种印象显然是不正确的。

我在 10.6 下看到的行为是,如果我第一次启动该应用程序,它会要求输入密码。如果我几乎立即启动,它就不会。但是,如果我等待足够长的时间,它会再次要求输入密码。在这整个过程中,辅助工具不会改变。

任何人都可以指出将其定义为正确行为的文档吗?

最佳答案

如果有人感兴趣,这(可能)被证明是一个错误并且已经被提交。雷达://10280469

系统目前的工作方式是,无论SMJobBless功能是否需要安装帮助工具,每次都会要求输入管理员密码。该错误(可能)是,如果不需要安装帮助工具(例如,它已经安装并且与应用程序包中的版本相同),则不应发出管理员密码请求。

因此,这意味着需要在调用 SMJobBless 之前确定是否需要安装辅助工具,并且只有在已知需要安装辅助工具的情况下才应调用 SMJobBless .

就我而言,我只需要检查是否安装了该工具(SMJobCopyDictionary 处理此问题),如果安装了该工具,则检查其版本是否比我的应用程序包中的工具版本旧。

下面是一些(不完整)代码,用于检查该工具是否已安装以及版本是什么。

还有另一种方法可以对帮助工具进行版本检查,即帮助工具接收对其版本的请求并发送回版本回复。就我个人而言,我喜欢下面的方法,但想提一下这个替代方案,因为在某些情况下它可能是最佳路径。

NSDictionary* installedHelperJobData;

installedHelperJobData = (NSDictionary*)SMJobCopyDictionary( kSMDomainSystemLaunchd, (CFStringRef)@"com.apple.bsd.SMJobBlessHelper" );

NSString* installedPath = [[installedHelperJobData objectForKey:@"ProgramArguments"] objectAtIndex:0];
NSURL* installedPathURL = [NSURL fileURLWithPath:installedPath];

NSDictionary* installedInfoPlist = (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)installedPathURL );
NSString* installedBundleVersion = [installedInfoPlist objectForKey:@"CFBundleVersion"];
NSInteger installedVersion = [installedBundleVersion integerValue];

NSLog( @"installedVersion: %ld", (long)installedVersion );

NSBundle* appBundle = [NSBundle mainBundle];
NSURL* appBundleURL = [appBundle bundleURL];

NSURL* currentHelperToolURL = [appBundleURL URLByAppendingPathComponent:@"Contents/Library/LaunchServices/com.apple.bsd.SMJobBlessHelper"];
NSDictionary* currentInfoPlist = (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)currentHelperToolURL );
NSString* currentBundleVersion = [currentInfoPlist objectForKey:@"CFBundleVersion"];
NSInteger currentVersion = [currentBundleVersion integerValue];

NSLog( @"currentVersion: %ld", (long)currentVersion );

关于macos - SMJobBless - 有关何时要求管理员密码的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7603226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com