iOS Hacker Keychain相关The executable was signed with invalid entitlements

添加钥匙串文件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的前缀,但是具体是什么值我们并不知道,可以通过代码来获取。如下:

- (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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值