我正在尝试从具有相同标识符(相同配置文件)的另一个应用程序访问应用程序设置的钥匙串数据。我使用这个链接来实现这一点。
钥匙串数据的保存正常进行,我得到以下语句的 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. */
我明白了,找不到该项目,但为什么在设备和模拟器中有所不同。