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 339 forks source link

Keys are being removed when iphone locked #95

Closed Ram-Knoxville closed 6 years ago

Ram-Knoxville commented 7 years ago

Everytime i lock my iphone all my keys go away for some reason.

is there a way to fix this ?

Thanks in advance

Ram-Knoxville commented 7 years ago

I run a couple of processes when the phone is locked, and this issue is really complicating things up for me. Is causing my app to crash since it finds nil on key values previously saved

jrendel commented 7 years ago

Are you trying to access the keys while the phone is locked or you mean after unlocking it they are gone? By default, keychain wrapper saves items to only be accessible when the device is unlocked. If you want to change the default accessibility, you can pass it as a parameter on your set requests. See KeychainItemAccessibility for the different options.

Ram-Knoxville commented 7 years ago

Can you give me an example of how to pass it as a parameter? i tried this KeychainWrapper.standard.set(deviceModel, forKey: "deviceModel", KeychainItemAccessibility: kSecAttrAccessibleAlways)

but it wouldnt let me

Thanks in advance @jrendel

Ram-Knoxville commented 7 years ago

I also found out that if my phone doesn't have a unlock password it works perfectly on background, but as soon as i add a passcode to my phone, the Keys disappear

jrendel commented 7 years ago

I think what you are looking for is:

KeychainWrapper.standard.set(deviceModel, forKey: "deviceModel", KeychainItemAccessibility: .always)
apsoftware123 commented 6 years ago

@jrendel that works, the team I work with found it to be a solution for this problem.