Storing keys in KeyChain with KeyChainItemWrapper

I’m using KeyChainItemWrapper class, provided by Apple’s Sample Code to save the authentication token to the keychain.

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier"JetTaxiApp_AuthToken" accessGroup:nil];  

But when I’m trying to set the value to keychain, an odd exception is raised

  • NSDate returns wrong year
  • iOS init UIWebView to clear navigation history
  • local declaration hides instance variable warning
  • is NSLog() stored on the device (iPhone etc)? If so, where?
  • How to show in UIImage just a part of image?
  • Caching on AFNetworking 2.0
  • [_authenticationTokenKeychain setObject:authenticationToken forKey: @"auth_token"];

    Terminating app due to uncaught exception
    ‘NSInternalInconsistencyException’, reason: ‘Couldn’t add the Keychain

    The keychain doesn’t exist yet (at the moment of this call)
    What can cause this exception?

    2 Solutions Collect From Internet About “Storing keys in KeyChain with KeyChainItemWrapper”

    You need to use standard keys, so here your @"auth_token" is incorrect.

    The keys that can be used for this purpose and the possible values for each key are listed in the “Keychain Services Constants” section.

    source, with list of valid constants: Keychain Services Reference

    For instance, you can use:

    [_authenticationTokenKeychain setObject:authenticationToken forKey: (__bridge NSString *)kSecValueData];

    [_authenticationTokenKeychain setObject:authenticationToken forKey: @"auth_token"];  

    For code snippet above, key param is only can use the keys provided from sdk.
    You can find all in SecItem.h