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

Lockbox unarchiveObjectForKey: returns nil sometimes #54

Open
maxencecornu opened this issue Jul 8, 2016 · 2 comments
Open

Lockbox unarchiveObjectForKey: returns nil sometimes #54

maxencecornu opened this issue Jul 8, 2016 · 2 comments

Comments

@maxencecornu
Copy link

Hello,

I use LockBox to store a refresh token and some urls, but sometimes when I call [Lockbox unarchiveObjectForKey:myKey] it returns nil. I don't know why :/

Here is how I save the data : (the infos came from a WS call)

[Lockbox archiveObject:oauthDico[@"baseUrl"] forKey:kOAuthBaseUrl]; [Lockbox archiveObject:oauthDico[@"getTokenEndpoint"] forKey:kOAuthTokenEndPoint]; [Lockbox archiveObject:oauthDico[@"refreshTokenEndpoint"] forKey:kOAuthRefreshTokenEndPoint];`

and this is how I retrieve it :

NSString* requestUrl = [NSString stringWithFormat:@"%@%@", [Lockbox unarchiveObjectForKey:kOAuthBaseUrl], [Lockbox unarchiveObjectForKey:kOAuthTokenEndPoint]];

and as I told, sometimes, I didn't figured out when excatly, the unarchive method returns nil, which is very problematic for a login url :p

Thanks for your help
Max

@granoff
Copy link
Owner

granoff commented Jul 8, 2016

That is odd indeed.

At the risk of stating the obvious, have you tried examining the contents of the dictionary oauthDico before you store values from it? If, for example, any of those values were nil, Lockbox would assume that you want to remove the associated key from the Keychain. (That is, storing a nil value removes the associated key from the Keychain.) Put another way, Lockbox would not complain about "storing" a nil value. When you then tried to retrieve the value for a key that is not in the Keychain, Lockbox returns nil.

I would start by being a bit more verbose with your code, at least to try to see where this problem is coming from. Verify (perhaps using NSAssert statements while developing the code) that values you expect to be non-nil are in fact not nil, for example.

...unless you've already done all that...

Are you certain there isn't a timing issue with fetching the values, storing the values, and then retrieving the values? Is it possible that you are retrieving the values before they have actually been saved to the Keychain? Without seeing your whole app, I am just throwing out ideas here. :)

@maxencecornu
Copy link
Author

Hello,

Thanks for your answer. I will check the non-nil value with asserts and control the timing. If I have the problem again, I'll let you know. Please leave this issue open for a month if you don't mind, to be sure on my side that all is ok.

Max

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

2 participants