0

I am using Apple KeyChainItemWrapper to store to keychain.

The problem is if I log the stored data directly after saving (by instantiate a new keychainItem with the same identifier) I can see the data. But when I kill the app and reopen it it returns nil.

This is how i save to keychain:

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



NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

[dict setObject:@{@"email": @"example@aol.com"} forKey:@"data"];

NSData *dictionaryRep = [NSPropertyListSerialization dict format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
NSLog(@"NSPropertyListSerialization error: %@", error);


[keychain setObject:@"test" forKey:(id)kSecAttrAccount];
[keychain setObject:(__bridge id)(kSecAttrAccessibleAlwaysThisDeviceOnly) forKey:(__bridge id)(kSecAttrAccessible)];
[keychain setObject:dictionaryRep forKey:(id)kSecValueData];

and this is how i access the value:

KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"test" accessGroup:nil];
NSData *infoData = [keychain objectForKey:(id)kSecValueData];
NSError* error;
NSDictionary *infoDictionary = [NSPropertyListSerialization propertyListWithData:infoData options:NSPropertyListImmutable format:nil error:&error];
NSLog(@"KeychainItemWrapper test : %@", infoDictionary);

Thank you for your help

zizoodiesel
  • 197
  • 1
  • 13
  • UserDefaults has this thing where if you kill the app from Xcode your properties won't persist because the lifecycle gets interrupted or something like that. Is it possible something similar is happening to you here? – Daniel Sep 08 '19 at 20:13
  • I also tried to open the app manually because i thought that but when relaunch with xcode it also logs nil. Maybe is something broken with my keychain? – zizoodiesel Sep 08 '19 at 20:16

0 Answers0