将钥匙串共享添加到已有用户的生产应用程序

时间:2014-10-15 20:12:49

标签: ios xcode keychain

我们已经发布了一款iOS应用。 IDE是XCode6。我想添加钥匙串共享以从iOS 8共享扩展程序访问应用程序中存在的sessionID。

问题是,只要打开钥匙串共享,就无法再访问已存在的sessionID。

只要关闭钥匙串共享,就可以访问它。

这个字典被传递到SecItemCopyMatching,无论“Keychain Groups:”是什么,只要启用了keychain共享,它总是返回-25300(未找到)。

[0] (null)  @"svce" : @"SESSION_ID_KEY"   
[1] (null)  @"r_Data" : @"1"    
[2] (null)  @"m_Limit" : @"m_LimitOne"  
[3] (null)  @"class" : @"genp"  
[4] (null)  @"acct" : @"SESSION_ID_KEY"   
[5] (null)  @"pdmn" : @"ck" 

知道为什么访问密钥可能不起作用?我尝试使用捆绑包前缀和名称设置kSecAttrAccessGroup,它仍然无法在模拟器上运行。

2 个答案:

答案 0 :(得分:7)

希望我得到你的回答和赏金:)

我原本遇到同样的问题并遇到过这篇文章,我知道你提到过你尝试使用捆绑前缀和名称。但是让我们进行一次健全检查。

MyApp.entitlementsMyApp Extension.entitlements中我将Keychain Access Groups设置为$(AppIdentifierPrefix)com.company.MyApp(这是默认设置)。

我使用此SO回答https://stackoverflow.com/a/20340883访问了ABCD1234(又名AppIdentifierPrefix值)的值,但是硬编码可能不是最佳做法,所以请考虑将此解决方案看作[keychainItem setObject:@"ABCD1234.com.company.MyApp" forKey:(__bridge id)kSecAttrAccessGroup]; 3}}

然后在我的应用程序中注意我添加的所有内容以使我当前的代码工作如下: 更新项目之前{{1}},我现在可以访问分享扩展程序中的钥匙串项目。

答案 1 :(得分:1)

几个月前,我在iOS 7中实现应用内通信时遇到了类似的问题。 我在Apple's GenericKeyChain sample project上发现了这句话:

        // Apps that are built for the simulator aren't signed, so there's no keychain access group
        // for the simulator to check. This means that all apps can see all keychain items when run
        // on the simulator.
        //
        // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
        // simulator will return -25243 (errSecNoAccessForItem).

因此,如果您在Simulator上进行测试,则需要删除“kSecAttrAccessGroup”。

在设备上,它应该使用此密钥。