ionic-team / cordova-plugin-ios-keychain

Apache Cordova (PhoneGap) plugin
Other
62 stars 44 forks source link

Callbacks always return `null` #4

Closed TomSeldon closed 7 years ago

TomSeldon commented 8 years ago

I've tried using this plugin as described in README.md but I can't seem to get it to work. There are no errors, but on setting and getting a key/value the success callback is always called with null as the only argument.

Am I doing something wrong?

See below output which was run on an iPad running iOS9:

screen shot 2016-08-11 at 09 33 32

I'd expect the final call, Keychain.get(onSuccess, onFail, 'someKey', 'message') to call the success callback with value (the string set in the previous call). This doesn't happen.

tmct commented 8 years ago

This might be caused by #5 - on our devices the Objective-C was never successfully setting the value in the keychain because it was trying to use TouchID

Gilgamoosh commented 8 years ago

I am also having this issue, and I noticed something else that is weird as well. The success function (argument 1 of Keychain.get) takes a 'value'. If I check that value in the function, for example: function (value) { alert(value); } Then in the alert I get that the value is true/false based on what I set the key's value to be. But if I try to assign that value in the function, like so:

var example;
Keychain.get( function (value) { example = value; alert(example); }, . . .[other arguments]. . .);
alert(example);

then I find that the alert inside Keychain.get shows example having a value equal to the key's value, but the alert outside Keychain.get shows example having no value.

This seems related so I'm noting it here instead of creating another issue, but I could be completely wrong on that.

tmct commented 8 years ago

That's just because your third line (the alert) is not guaranteed to be called after the asynchronous callback that sets example's value :)

Gilgamoosh commented 8 years ago

Ah, I didn't catch that. Thank you. I've applied the change from #5 so I'll see how that goes. Update for information: The change that fixes #5 can be found in #8

UPDATE: The change for #5 did not fix the issue.

mlynch commented 8 years ago

Can you try the new version in master? I can't reproduce this...it might have just been fixed with some random changes. Also try a different key name, sometimes that uses stale data/metadata and keychain gets angry

mlynch commented 7 years ago

Closing as most likely fixed