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

Exception thrown when unarchiveObjectForKey called on ios 8 #52

Closed
ninjitaru opened this issue Mar 17, 2016 · 7 comments
Closed

Exception thrown when unarchiveObjectForKey called on ios 8 #52

ninjitaru opened this issue Mar 17, 2016 · 7 comments

Comments

@ninjitaru
Copy link

Hi,

I have notice that because the use of[[NSKeyedUnarchiver alloc] initForReadingWithData:data],
It will throw NSInvalidArgumentException
[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (xxx,xxx,xxx,0x0, 0x0, 0x0, 0x0, 0x0)

This only happens on ios8 ... it won't happen on ios9 ...
but It think it might be safer to catch the exception within unarchiveObjectForKey.. so ppl using this library won't have unexpected exception happen to them
Thanks

@granoff
Copy link
Owner

granoff commented Mar 17, 2016

At the risk of stating the obvious, you cannot mix the new Lockbox v3 APIs with data stored using pre-v3 APIs. That is to say, if you had stored a string using -setString:forKey: you cannot then use -unarchiveObjectForKey: to retrieve it. You would see the behavior you describe (or worse). I can't imagine this scenario would work on any version of iOS, so your last comment about it working on iOS9 is perplexing. Can you share some code so I can see what you're actually doing?

@ninjitaru
Copy link
Author

I did not know that I cannot mix it, but I did mix them with the intend on retrieve key value while migrating existing v2 API codes

NSString *object =  [Lockbox unarchiveObjectForKey:key];
if(!object) {
     object = [Lockbox stringForKey:key]; 
     if(object) {
        [Lockbox archiveObject:object forKey:key accessibility:kSecAttrAccessibleWhenUnlocked];
     }
}
return object;

I was relying on the expectation that -unarchiveObjectForKey: return nil if its not able to unarchive the object correctly with the key which seem to be the case on iOS9 but exception is thrown on iOS8

@granoff
Copy link
Owner

granoff commented Mar 17, 2016

Your use of both the v2 and v3 APIs to first fetch, and then store, a value for a key is correct. What i meant by not mixing was that you cannot store a key using a v2 API and then retrieve it properly using a v3 API. Your migration code, which fetches then stores, is fine.

I see what you're saying about catching the error. I'll look into it.

@marcelosalloum
Copy link

Hey @granoff, any hints when v 3.0.1 will be available in Cocoapods?

@granoff
Copy link
Owner

granoff commented Aug 4, 2016

Hm. Thought it would be by now. The tags are there, the podspec seems right. Investigating...

@granoff
Copy link
Owner

granoff commented Aug 4, 2016

Available now. Sorry!

@marcelosalloum
Copy link

Thanks a lot!

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

3 participants