添加钥匙串文件KeychainAccessGroups.plist,然后新建Array, 新建String,填写要名称之后,在iOS8测试运行是没有问题的,但是在iOS10下运行提示如下错误
The executable was signed with invalid entitlements.
The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile. (0xE8008016).
如果把工程设置里的Code_Sign_Entitlements给去掉的话,可以运行,但是肯定是访问不了Keychain。搞了一整天,终于研究出了解决方法
解决方法:选择工程->Capabilities->Keychain Sharing开启,这时会自动生成一个entitlements的文件,打开这个文件可以看到Keychain Access Groups里有一个值是$(AppIdentifierPrefix)younrame.testproject。我们在代码修改KeychainItemWrapper里accessGroup的值$(AppIdentifierPrefix)younrame.testproject,现在有一个疑问AppIdentifierPrefix的值是什么呢?这是开发者ID的前缀,但是具体是什么值我们并不知道,可以通过代码来获取。如下:
The executable was signed with invalid entitlements.
The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile. (0xE8008016).
如果把工程设置里的Code_Sign_Entitlements给去掉的话,可以运行,但是肯定是访问不了Keychain。搞了一整天,终于研究出了解决方法
解决方法:选择工程->Capabilities->Keychain Sharing开启,这时会自动生成一个entitlements的文件,打开这个文件可以看到Keychain Access Groups里有一个值是$(AppIdentifierPrefix)younrame.testproject。我们在代码修改KeychainItemWrapper里accessGroup的值$(AppIdentifierPrefix)younrame.testproject,现在有一个疑问AppIdentifierPrefix的值是什么呢?这是开发者ID的前缀,但是具体是什么值我们并不知道,可以通过代码来获取。如下:
- (NSString *)GetAppIdentifierPrefix {
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
kSecClassGenericPassword, kSecClass,
@"bundleSeedID", kSecAttrAccount,
@"", kSecAttrService,
(id)kCFBooleanTrue, kSecReturnAttributes,
nil];
CFDictionaryRef result = nil;
OSStatus status = SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result);
if (status == errSecItemNotFound)
status = SecItemAdd((CFDictionaryRef)query, (CFTypeRef *)&result);
if (status != errSecSuccess)
return nil;
NSString *accessGroup = [(NSDictionary *)result objectForKey:kSecAttrAccessGroup];
NSArray *components = [accessGroup componentsSeparatedByString:@"."];
NSString *strAppIdentifierPrefix = [[components objectEnumerator] nextObject];
CFRelease(result);
return strAppIdentifierPrefix;
}