KeyChain集成导致“丢失权利”错误导致崩溃 – 通过命令行构建

我遇到一些KeyChain代码的问题导致通过xcodebuild创建的档案在作为ad-hoc应用程序分发并在设备上运行时崩溃。 该问题不会影响通过Xcode创建的构建 – 只有通过命令行创建的构建。

抛出错误的代码:(我正在使用此处找到的KeyChain库)

 KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"myapp" accessGroup:nil]; NSString *testKeychain = (NSString *)[keychain objectForKey:(__bridge id) kSecAttrAccount]; if (testKeychain.length) { NSLog(@"KeyChain value for kSecAttrAccount: %@", testKeychain); } else { NSLog(@"No KeyChain value for kSecAttrAccount"); } [keychain setObject:@"Shared KeyChain value!" forKey:(__bridge id) kSecAttrAccount]; // <-- error thrown here 

“遗失权利”错误

 2012-06-15 10:03:20 AM +0000 securityd MyApp [138] SecItemCopyMatching: missing entitlement 2012-06-15 10:03:20 AM +0000 MyApp No KeyChain value for kSecAttrAccount 2012-06-15 10:03:20 AM +0000 securityd MyApp [138] SecItemCopyMatching: missing entitlement 2012-06-15 10:03:20 AM +0000 securityd MyApp [138] SecItemAdd: missing entitlement 2012-06-15 10:03:20 AM +0000 MyApp *** Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/davidbjames/XCode/.../KeychainItemWrapper.m:305 

权利文件:

 keychain-access-groups  $(AppIdentifierPrefix)$(CFBundleIdentifier)  

xcodebuild输出似乎正在处理授权文件:

 setenv CODE_SIGN_ENTITLEMENTS MyApp/MyApp.entitlements .. ProcessProductPackaging MyApp/MyApp.entitlements /etc/etc/build/MyApp.xcent .. builtin-productPackagingUtility /etc/etc/MyApp.entitlements -entitlements -format xml -o /etc/etc/MyApp.xcent 

代码在模拟器,调试设备和ad-hoc分发中无错误地运行。 唯一的问题是通过命令行构建发生的。 我错过了什么?

此错误表示您的应用的权利存在问题。 根据我的经验,原因通常是应用程序权利中的应用程序标识符前缀与配置文件中的应用程序标识符前缀不匹配。

要进行validation,请使用codesign工具查看应用的权利:

 codesign -d --entitlements - MyApp.app/ 

然后,将应用程序标识符前缀与配置文件中的应用程序标识符前缀进行比较:

 cat MyApp.app/embedded.mobileprovision 

经过长时间的工作,我找到了解决这个问题的方法,并相应地修改了floatsign.sh脚本( https://gist.github.com/mediabounds/1367348 ) – 权利必须像@sglist所说的那样更新。 您可以在这里找到实现: https : //gist.github.com/Weptun/5406993

我认为这一行是错误的:

 [[KeychainItemWrapper alloc] initWithIdentifier:@"myapp" accessGroup:nil] 

您需要在那里传递您的访问组名称。 它可能会或可能不会解决您的问题,这些事情有点“敏感”。