hel*_*ght 7 xcode keychain ios
我们有一个已发布的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"
Run Code Online (Sandbox Code Playgroud)
知道为什么访问密钥可能不起作用?我尝试使用捆绑包前缀和名称设置kSecAttrAccessGroup,但它仍然无法在模拟器上运行.
希望我得到你的答案和赏金:)
我最初遇到了同样的问题并遇到过这篇文章,我知道你提到过你试过捆绑前缀和名称.但是让我们进行一次健全检查.
在MyApp.entitlements和MyApp Extension.entitlements我在Keychain Access Groups设置为$(AppIdentifierPrefix)com.company.MyApp(这是默认值).
我使用这个SO答案/sf/answers/1423861841/访问了ABCD1234(aka AppIdentifierPrefix值)的值,但硬编码可能不是这里的最佳做法,所以考虑看这个像这样的解决方案https://stackoverflow.com/a /2588957分之11841898
然后在我的应用程序中注意我添加的所有内容使我当前的代码工作如下:
[keychainItem setObject:@"ABCD1234.com.company.MyApp" forKey:(__bridge id)kSecAttrAccessGroup];在更新项目之前,我现在可以访问我的共享扩展中的钥匙串项目.
几个月前,我在 iOS 7 中实现应用程序间通信时遇到了类似的问题。我在Apple 的 GenericKeyChain 示例项目中发现了这样的评论:
Run Code Online (Sandbox Code Playgroud)// 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).
因此,如果您在模拟器上进行测试,则需要删除“kSecAttrAccessGroup”。
在设备上它应该与此键一起使用。
| 归档时间: |
|
| 查看次数: |
2702 次 |
| 最近记录: |