简体   繁体   English

iOS,钥匙串 kSecAttrAccount 未保存

[英]iOS, Keychain kSecAttrAccount not saving

When fetching the data:获取数据时:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
NSString *user = [[NSUserDefaults standardUserDefaults] valueForKey:@"ACC"];
NSString *pass = [keychain objectForKey:CFBridgingRelease(kSecAttrAccount)];

When saving the data:保存数据时:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
[[NSUserDefaults standardUserDefaults] setObject:[jsonResult objectForKey:@"user"] forKey:@"ACC"];
[keychain setObject:[jsonResult objectForKey:@"token"] forKey:CFBridgingRelease(kSecAttrAccount)];

I'm re-using code i've used a couple years ago.我正在重新使用几年前使用过的代码。 However now i'm experiancing issues with part of it not working correctly.但是,现在我遇到了部分无法正常工作的问题。

For what it's worth, i'm using the KeyChainItemWrapper Version: 1.2 ( Objective-c )对于它的价值,我使用的是 KeyChainItemWrapper 版本:1.2(Objective-c)

The [[NSUserDefaults standardUserDefaults] valueForKey:@"ACC"] works fine, and is saved, however storing a value for CFBridgingRelease(kSecAttrAccount) doesn't save. [[NSUserDefaults standardUserDefaults] valueForKey:@"ACC"]工作正常,并被保存,但是存储CFBridgingRelease(kSecAttrAccount)的值不会保存。 When running the fetch code, after the save code, i only get (null) .运行提取代码时,在保存代码之后,我只得到(null)

I'm using xcode 8.3.1 with simulator version 10, running iPhone 7 version 10.3.我使用 xcode 8.3.1 和模拟器版本 10,运行 iPhone 7 版本 10.3。

The newest IDE version & iOS version is the only thing that has changed最新的 IDE 版本和 iOS 版本是唯一改变的东西

For Saving and Retrieving Data to Key chain make sure to use the Apple default ARC release.对于将数据保存和检索到钥匙链,请确保使用 Apple 默认的 ARC 版本。

Save To key chain:-保存到钥匙链:-

KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"Your identifire" accessGroup:nil];
  [keychainItem setObject:appleUserId forKey:(id)CFBridgingRelease(kSecAttrAccount)];

Retrieve data from the key chain:-从钥匙链中检索数据:-

KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"Your identifire" accessGroup:nil];
        
        NSString *savedUserID = [keychainItem objectForKey:(id)CFBridgingRelease(kSecAttrAccount)];

For More info check the official link:有关更多信息,请查看官方链接:

https://developer.apple.com/documentation/foundation/1587932-cfbridgingrelease https://developer.apple.com/documentation/foundation/1587932-cfbridgingrelease

https://gist.github.com/dhoerl/1170641 https://gist.github.com/dhoerl/1170641

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM