5

I'm using SSKeychain to store a session token. When I compile and run the app from XCode, sometimes the token cannot be found (seems like it works sporadically). However, if I unplug my device and run the app without XCode, the token is back, 10/10 times. I'm not sure if this is a problem with SSKeychain or with Keychain in general. The code I'm using to store and read values is the following:

- (void)setSecureValue:(NSString *)value forKey:(NSString *)key
{
    [SSKeychain setPassword:value forService:kServiceName account:key];
}

- (NSString *)secureValueForKey:(NSString *)key
{
    if (key != nil)
    {
        return [SSKeychain passwordForService:kServiceName account:key];
    }
    return nil;
}

Many issues revolving Keychain access seem to be resolved by realizing that the keychain is not a data storage and that it can be emptied at times (due to memory warnings, for example). However, since I always run on the same device, and the token is still there after unplugging and running again, I don't see how this could be the issue here.

Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82

1 Answers1

2

This is a bug of the keychain itself. If you are debugging the app on device, the app security needs to be breached to enable the debugging mode and that's why the keychain doesn't work somehow

Pavel Smejkal
  • 3,600
  • 6
  • 27
  • 45
  • I see. Is there any workaround for this? I assume that a lot of big apps use keychain, and building something like a login flow is so hard if you can't rely on the keychain to work on the device. – Daniel Larsson Mar 19 '16 at 16:48
  • I don't know about any workaround. What I do is that I just use simulator as much as I can :) You could also do some special DEBUG solution – I mean don't use keychain when in the debug mode :-/ – Pavel Smejkal Mar 19 '16 at 22:32