IOS Keychain Entry Value Causes Code Error -34018

I have an iOS application that stores some confidential information in a keychain. When I write values ​​to the keychain, I get error code -34018.

I am currently using the Apple iOS class KeyChainItemWrapper.

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

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

This problem does not occur every time, but intermittently. As soon as I get this error, I can no longer write any values ​​to the keychain.

I printed the error description as follows:

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

and this is what the error throws:

 Error: Error Domain=NSOSStatusErrorDomain Code=-34018 "The operation couldn't be completed. (OSStatus error -34018.)" 
+24
ios keychain keychainitemwrapper
Jan 03 '15 at 6:42
source share
7 answers

It seems like this is a bug in Keychain that only appears when starting the application from xcode. See here: https://github.com/soffes/sskeychain/issues/52

We debugged it a lot, and it seems the problem is with the key chain when the application starts from the background. This only happens with the debugger (i.e. when starting from Xcode). We believe that in our case the problem may be related to the debugger supporting the application even if it should be killed by the OS. We tried to actually launch the application, and then put it in the background and run many other applications to take up RAM. With the debugger, an error occurred while resuming the application from the background, while without the debugger it was not (we performed at least 10 tests each).

+34
Jan 31 '15 at 21:14
source share

If someone comes here with this error and XCode8 with iOS10 , maybe you need to enable KeyChain Share on the Capabilities tab:

Activate KeychainShare ON enter image description here

+23
Oct 19 '16 at 8:00
source share

As already mentioned, this is a Keychain error that Apple has been aware of and has been aware of since at least mid-2015.

As of March 22, 2016, Apple said:

We believe that these problems were resolved in iOS 9.3.

iOS 9.3 was released on March 21, 2016.

See the stream: https://forums.developer.apple.com/thread/4743

To quote an Apple employee answer:

Mar 22, 2016 3:28 AM

Ok last. This is a complex problem with several possible causes:

  • Some examples of the problem are caused by an incorrect subscription to the application. You can easily distinguish this case because the problem is 100% reproducible.

  • Some examples of the problem are caused by an error in how iOS supports application development (i.e. 23, 991, 853). Debugging this was complicated by the fact that another error in the OS (t. 23,770,418) masked its effect, which meant that the problem arose only when the device was under memory pressure.

    We believe that these problems were resolved in iOS 9.3.

  • We suspect that even more causes of this problem may arise.

So, if you see this problem on a user device (which was not supported by Xcode) that is running iOS 9.3 or later, make an error message file. Try to include the device’s system log in the error report (I understand that it can be difficult when working with client devices, one of them is to ask the client to install Apple Configurator, which allows them to view the system log). And if you make a file with an error, send your error number, only for writing.

On behalf of Apple Id, I would like to thank everyone for their efforts to find this rather terrible problem.

Share and enjoy

+4
Mar 22 '16 at 21:09
source share

It made me 2 hours before I found a quick “fix” - reboot your iOS device

Quote from the discussion at http://forums.developer.apple.com/thread/4743 ,

From user littledetails

As others have reported, this mysterious error in the keychain is most easily viewed when launched through Xcode with an attached debugger. As soon as the error starts, the key fob does not seem correct, regardless of the memory pressure , until the device restarts .

When I rebooted my device, the error disappeared, allowing me to continue testing. Not sure what else to do. In my situation, switching to NSUserDefaults or some other storage solution was not possible.

+3
Oct. 15 '15 at 1:17
source share

One way to get around this problem with keychain is to use dispatch_async so that the application can start. This works when the application opens from the background. Also make sure you have the kSecAttrAccessibleAfterFirstUnlock accessibility kSecAttrAccessibleAfterFirstUnlock on the keychain.

  dispatch_async(dispatch_get_main_queue(), ^{ // save/write to keychain }) 
+2
Sep 11 '15 at 15:42
source share

According to the answers of @iCaramba. I found a workaround:

  • Stop the task to kill the application (if you are already using the application)
  • Launch the application on your device manually. DO NOT use Xcode
  • Use Xcode to restart the application
0
Nov 29 '15 at 16:13
source share

I use the GenericKeychain classes from apple:

https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007797-Intro-DontLinkElementID_2

 struct KeychainConfiguration { static let serviceName = "MyAppService" /* Specifying an access group to use with `KeychainPasswordItem` instances will create items shared accross both apps. For information on App ID prefixes, see: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/AppID.html and: https://developer.apple.com/library/ios/technotes/tn2311/_index.html */ // static let accessGroup = "[YOUR APP ID PREFIX].com.example.apple-samplecode.GenericKeychainShared" /* Not specifying an access group to use with `KeychainPasswordItem` instances will create items specific to each app. */ static let accessGroup: String? = nil } 

In this file, I indicated my own accessGroup in this line static let accessGroup = "[YOUR APP ID PREFIX] .com.example.apple-samplecode.GenericKeychainShared"

After returning to static let accessGroup: String? = nil problem disappeared. :)

0
Dec 6 '17 at 15:32
source share



All Articles