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



我似乎找不到任何关于这方面的文档,所以希望有人能确认我在苹果的样本SMJobBless代码中看到的行为。

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

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

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

有谁能指出将此定义为正确行为的文档吗?

如果有人感兴趣的话,这(可能)是一个bug,并且已经被归档了。rdar://10280469

系统目前的工作方式是,无论SMJobBless函数是否需要安装helper工具,每次都会要求输入admin密码。这个bug(可能)是,如果helper工具不需要安装(例如,它已经安装并且与应用程序包中的版本相同),则不应该发出admin密码请求。

因此,这意味着需要在调用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 );

最新更新