Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occasional Nil value for String. #42

Open
ghost opened this issue Aug 20, 2015 · 3 comments
Open

Occasional Nil value for String. #42

ghost opened this issue Aug 20, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 20, 2015

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?

@granoff
Copy link
Owner

granoff commented Aug 20, 2015

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?

@ghost
Copy link
Author

ghost commented Aug 21, 2015

I've only just started assigning the value to a strong property, but the main issue stems from the following post on StackOverflow.

http://stackoverflow.com/questions/10536859/ios-keychain-not-retrieving-values-from-background/10583042#10583042

@granoff
Copy link
Owner

granoff commented Aug 21, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant