jrendel / SwiftKeychainWrapper

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.
MIT License
1.59k stars 340 forks source link

[Very Rare] Key Chain is inaccessible/return nil #147

Open anjananoup opened 4 years ago

anjananoup commented 4 years ago

I am using SwiftKeychainWrapper in my project. It's working most of the time without any issue. But in very few cases My app is unable to access KeyChain. And after that, no matter what, user restarting app, keyChain is always return nil.

Pod version: 3.4.0

Implementation logic: On app very first launch (Fresh Install case) (Not update or upgrade case), I remove old keyChain Data Using: KeychainWrapper.standard.removeAllKeys(), thus my app can generate new value and use them. And other cases I always uses KeychainWrapper.standard.set(.... && KeychainWrapper.standard.string(.... apis to get and set values for my app.

Is there any issue for accessing KeychainWrapper.standard just after removing All old values? Or this is some king of bug?

niteshborad commented 4 years ago

I am having the same issue. For just one of our clients (around 2000), KeychainWrapper.standard.string(... always returns nil. It is working fine for all other clients.

kunaltyagi26 commented 4 years ago

Hi @jrendel , Can you please help with this context as we are also facing this issue with one of our users.

iceboxi commented 3 years ago

I think it's the reason https://developer.apple.com/documentation/uikit/uiapplication/1622925-isprotecteddataavailable

You should check isprotecteddataavailablebefore access keychain, if it is false, you will get nil value.