iOS Keychain Data Lost Upon iPhone Memory Pressure

2019-06-28 01:17发布

问题:

I'm running an iOS app via a debugger on my iPhone 5s. I'm using the keychain to store a password (I'm using the KeychainItemWrapper example from Apple to store and retrieve my keychain items). About 99.99% of the time, the keychain retrieval works perfectly. However, there have been two cases in which my application could not get the password. For example, once, my phone was experiencing memory pressure and I had to restart the phone and relaunch the app. Upon the app relaunch, my app could no longer retrieve the password from the keychain. I wonder if this password loss was caused by this memory pressure? What other cases does iOS purge keychain data? Is there any way to present this??

回答1:

iOS keychain is very much unrelated with your app's memory pressure.

There could be 2 scenarios:

  1. Somehow you happen to reset your phone - Keychain data would be lost (unless your keychain is synced with icloud).
  2. You somehow called resetKeychainItem from your wrapper.

Can't help more without having a look at your code.



回答2:

You could probably not found the value temporary, as you can see in this question: KeychainItemWrapper not getting loaded on iOS 9 OSStatus -34018 (errSecMissingEntitlement) and the related question on apple's forum: https://forums.developer.apple.com/thread/4743