ios - saving in ios keychain is not persistent
问题描述
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
解决方案
推荐阅读
- symfony - 我如何在 Symfony 中制作日志
- c - posix_spawn() 的处理错误
- javascript - 如何将一个函数用于具有不同数据字段的多个表头
- json - 如何将 curl url 转换为 POSTMAN 请求
- c# - Aim Assist in Unity?
- r - Object not found - R
- macos - Connect TFS in visual studio 2017 macbook
- javascript - Webstorm + Flow + React:未解析的变量或类型 $Keys
- python - 如何构建动态 Web Scraper/Crawler:Python
- jquery - 使用不同数据源的 jQuery ui 自动完成