iOS Keychain写入值导致错误代码-34018 [英] iOS Keychain writing value results in error code -34018

查看:4276
本文介绍了iOS Keychain写入值导致错误代码-34018的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序,可以在钥匙串中存储一些敏感信息。
在将值写入钥匙串时,我收到错误代码-34018。

I have an iOS application that stores some sensitive information in the keychain. While writing values into the keychain, I am getting error code -34018.

我目前正在使用Apple的iOS KeyChainItemWrapper类。

I am currently using Apple's iOS KeyChainItemWrapper class.

以下两行代码都会收到相同的错误代码。

Both of the following lines of code receive the same error code.

OSStatus res1 = SecItemCopyMatching((__bridge CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes);
OSStatus res = SecItemUpdate((__bridge CFDictionaryRef)updateItem, (__bridge CFDictionaryRef)tempCheck);

此问题不是每次都发生,而是间歇性地发生。一旦我收到此错误,我就无法再将任何值写入钥匙串。

This issue does not occur every time, but intermittently. Once I get this error, I am no longer able to write any values to the keychain.

我打印了错误描述,如下所示:

I have printed the error description like so:

NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:res userInfo:nil];

这就是错误输出的内容:

and this is what the error prints out:

Error: Error Domain=NSOSStatusErrorDomain Code=-34018 "The operation couldn’t be completed. (OSStatus error -34018.)"


推荐答案

似乎这是Keychain中的一个错误,只有当您从xcode启动应用程序时才会出现该错误。请参阅此处: https://github.com/soffes/sskeychain/issues/52

Seems like this is a bug in Keychain, which only appears when you launch your app from xcode. See here: https://github.com/soffes/sskeychain/issues/52


我们调试了很多,当
应用程序从后台启动时,访问钥匙串似乎是一个问题。这只发生在调试器的
(即从Xcode启动时)。我们认为问题
在我们的情况下可能与调试器相关,即使它应该被操作系统杀死也能保持app
。我们实际上尝试运行
应用程序,然后将其置于后台并启动许多其他应用程序以占用
RAM。使用调试器时,从
背景恢复应用程序时出现错误,而没有调试器则没有(我们每次运行至少
10次测试)。

We debugged it a lot and it seems an issue accessing the keychain when the app is launched from the background. This is only happening with the debugger (i.e. when launched from Xcode). We think the issue might be related in our case to the debugger keeping alive the app even if it should be killed by the OS. We tried in fact to run the app and then put it in background and launch many other app to occupy RAM. With the debugger the bug came up when resuming the app from the background, while without the debugger it didn't (we did run at least 10 tests each).

这篇关于iOS Keychain写入值导致错误代码-34018的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆