获取数据时:
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
NSString *user = [[NSUserDefaults standardUserDefaults] valueForKey:@"ACC"];
NSString *pass = [keychain objectForKey:CFBridgingRelease(kSecAttrAccount)];保存数据时:
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
[[NSUserDefaults standardUserDefaults] setObject:[jsonResult objectForKey:@"user"] forKey:@"ACC"];
[keychain setObject:[jsonResult objectForKey:@"token"] forKey:CFBridgingRelease(kSecAttrAccount)];我正在重新使用几年前使用过的代码。然而,现在我遇到了一些问题,其中有一部分不能正常工作。
不管怎样,我使用的是KeyChainItemWrapper版本: 1.2 ( Objective-c )
[[NSUserDefaults standardUserDefaults] valueForKey:@"ACC"]可以正常工作并被保存,但是为CFBridgingRelease(kSecAttrAccount)存储一个值并不能保存。当运行fetch代码时,在保存代码之后,我只得到(null)。
我在模拟器版本10中使用Xcode8.3.1,运行iPhone 7版本10.3。
最新的集成开发环境版本& iOS版本是唯一改变的版本
发布于 2021-01-21 13:39:04
为了将数据保存和检索到密钥链,请确保使用Apple默认的ARC版本。
保存到密钥链:-
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"Your identifire" accessGroup:nil];
[keychainItem setObject:appleUserId forKey:(id)CFBridgingRelease(kSecAttrAccount)];从密钥链检索数据:-
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"Your identifire" accessGroup:nil];
NSString *savedUserID = [keychainItem objectForKey:(id)CFBridgingRelease(kSecAttrAccount)];有关更多信息,请查看官方链接:
https://developer.apple.com/documentation/foundation/1587932-cfbridgingrelease
https://stackoverflow.com/questions/45941297
复制相似问题