Open ghost opened 9 years ago
How are you assigning the value returned from objectForKey:
? If you are assigning it to a strong
instance variable using dot notation, I would expect you to have access to the value all the time. If you are retrieving the value and assigning it to a variable that is something other than strong
, I am not surprised that it becomes nil
eventually, as the OS is releasing it because it thinks you're done with it. Can you post some code where you retrieve the value, etc?
I've only just started assigning the value to a strong property, but the main issue stems from the following post on StackOverflow.
Ah! I see. That post talks about the problem being solved by specifying a more permissive accessibility for the data. Lockbox supports data accessibility, the default being kSecAttrAccessibleWhenUnlocked
.
All the setXxx:forKey:
methods use this default value. But each set
method has a version available that lets you specify the accessibility you prefer, e.g. setString:forKey:accessibility:
. So for the data you need to access from the key chain while the device is locked or the app is backgrounded, use one of these methods with a more permissive accessibility, e.g. kSecAttrAccessibleAfterFirstUnlock
.
At the moment I am using Lockbox to store a sessionToken in keychain.
Occasionally Lockbox returns a nil value when returning the sessionToken string.
Should i be returning the value from Lockbox every time I make a network request, or should I be assigning it to a property within the application when it's first retrieved?
Is there an issue with getting data stored in keychain?