我正在尝试从具有相同标识符(相同配置文件)的另一个应用程序访问应用程序设置的钥匙串(keychain)数据。我用了 this link为达到这个。
钥匙串(keychain)数据的保存正常进行,我得到以下语句的 errSecSuccess (在模拟器和设备中)
OSStatus status = SecItemAdd((CFDictionaryRef)dictionary, NULL);
到目前为止一切都很好,但是当我试图取回我的应用程序 A 保存在另一个应用程序 B 中的凭据时,它在模拟器和设备中的工作方式不同。
在 iOS 模拟器 6.1 中,以下语句的状态为“0”。
OSStatus status = SecItemCopyMatching((CFDictionaryRef)searchDictionary, &foundDict);
在任何 iOS 设备中,我的状态都是“-25300”。
我知道这些是安全框架中的错误代码:
//errSecSuccess = 0, /* No error. */
//errSecUnimplemented = -4, /* Function or operation not implemented. */
//errSecParam = -50, /* One or more parameters passed to a function where not valid. */
//errSecAllocate = -108, /* Failed to allocate memory. */
//errSecNotAvailable = -25291, /* No keychain is available. You may need to restart your computer. */
//errSecDuplicateItem = -25299, /* The specified item already exists in the keychain. */
//errSecItemNotFound = -25300, /* The specified item could not be found in the keychain. */
//errSecInteractionNotAllowed = -25308, /* User interaction is not allowed. */
//errSecDecode = -26275, /* Unable to decode the provided data. */
//errSecAuthFailed = -25293, /* The user name or passphrase you entered is not correct. */
我明白了,找不到该项目,但为什么在设备和模拟器中有所不同。
最佳答案
据我所知,您在应用程序中处理的钥匙串(keychain)组默认情况下不会在系统上的其他应用程序之间共享。如果是这种情况,则意味着如果您设法找到另一个应用程序的组,您可以窃取他们的私有(private)钥匙串(keychain)项目,从而使钥匙串(keychain)提供的安全性无效。
因此,有一个称为钥匙串(keychain)访问组的概念,它允许公开定义您希望在您的应用程序之间共享的钥匙串(keychain)组。 documentation状态:
Enabling keychain sharing allows your app to share passwords in the keychain with other apps developed by your team
因此请注意,您只能与来自同一开发人员的其他应用程序(即您的其他应用程序)共享钥匙串(keychain)项目。
关于ios - 共享钥匙串(keychain)数据的两个应用程序在 iOS 模拟器中运行良好,但在设备中运行不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16979333/