我正在尝试向钥匙串写入一个条目,但它失败并返回代码为 -25243,该文档仅列出了“常见”错误代码,并将您指向“The Open Group”的方向以寻求帮助。我已经下载了该文档,但不知道在哪里查看,该文档长达 1000 多页,并且似乎列出了 #define 的负载。
任何人都可以帮忙吗?
在设备上运行时可能会看到此错误的原因有很多。我看到的两种情况都是在尝试使用访问组将值存储到钥匙串时发生的。
为确保您已正确设置所有这些内容:
好的,问题似乎是我试图在 kSecAttrAccessGroup 中存储一个值,将其更改为 kSecAttrDescription 并且一切都很好
有点晚了,但值得正确回答。尝试将访问组与模拟器中的钥匙串一起使用时会发生此错误。
请注意GenericKeychain示例中的此代码段 。
#if TARGET_IPHONE_SIMULATOR
// Ignore the access group if running on the iPhone simulator.
//
// 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).
#else
[genericPasswordQuery setObject:accessGroup forKey:(id)kSecAttrAccessGroup];
#endif
我最近遇到了这个问题,原来是我有多个开发人员帐户,而 Xcode 选择了“错误的”开发人员证书来签署我的调试版本。此证书与 App Id 不属于同一个开发者,因此该应用程序不再有权访问该钥匙串组。
一旦我强制代码签名使用正确的开发人员证书,错误就会消失。