0

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 )

The [[NSUserDefaults standardUserDefaults] valueForKey:@"ACC"] works fine, and is saved, however storing a value for CFBridgingRelease(kSecAttrAccount) doesn't save. When running the fetch code, after the save code, i only get (null).

I'm using xcode 8.3.1 with simulator version 10, running iPhone 7 version 10.3.

The newest IDE version & iOS version is the only thing that has changed

Simon.
  • 1,886
  • 5
  • 29
  • 62
  • A minor nitpick, you don’t have ownership of `kSecAttrAccount` so you should not use `CFBridgingRelease` as it will make ARC release `kSecAttrAccount`. But as it is a global constant, its not released anyway. See https://stackoverflow.com/questions/14207960 – Mats Aug 29 '17 at 15:46
  • Just use FDKeychain, available on GitHub. It's a simple wrapper class for keychain. It allows you to easily load/save passwords/etc. – Supertecnoboff Aug 30 '17 at 08:31

1 Answers1

0

For Saving and Retrieving Data to Key chain make sure to use the Apple default ARC release.

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://gist.github.com/dhoerl/1170641

Rohit Chaurasiya
  • 597
  • 5
  • 12