可能是您正在调用CFBundleCopyInfoDictionaryForURL
代码签名的帮助工具吗?
如果是这样,看起来这个函数似乎破坏了代码签名的有效性。(大概是因为CFBundle
修改了内存中的Info.plist数据,但这只是我的猜测。)
解决方案是使用SecCodeCopySigningInformation
读取帮助工具的版本信息:
-(NSString *) bundleVersionForCodeSignedItemAtURL:(NSURL *)url {
OSStatus status;
// Sanity check -- nothing begets nothing
if (!url) {
return nil;
}
// Get the binary's static code
SecStaticCodeRef codeRef;
status = SecStaticCodeCreateWithPath((CFURLRef)url, kSecCSDefaultFlags, &codeRef);
if (status != noErr) {
NSLog(@"SecStatucCodeCreateWithPath() error for %@: %d", url, status);
return nil;
}
// Get the code signature info
CFDictionaryRef codeInfo;
status = SecCodeCopySigningInformation(codeRef, kSecCSDefaultFlags, &codeInfo);
if (status != noErr) {
NSLog(@"SecCodeCopySigningInformation() error for %@: %d", url, status);
CFRelease(codeRef);
return nil;
}
// The code signature info gives us the Info.plist that was signed, and
// from there we can retrieve the version
NSDictionary *bundleInfo = (NSDictionary *) CFDictionaryGetValue(codeInfo, kSecCodeInfoPList);
NSString *version = [bundleInfo objectForKey:@"CFBundleVersion"];
// We have ownership of the code signature info, so we must release it.
// Before we do that, we need to hold onto the version otherwise we go
// crashing and burning.
[[version retain] autorelease];
CFRelease(codeInfo);
CFRelease(codeRef);
return version;
}
值得称赞的是:有关的重要信息CFBundleCopyInfoDictionaryForURL
来自Ian MacLeod'sSMJobKit
。