1

I heard that using keychain is better than using NSUserDefault.
The problem is that I have no idea how to use it.
I'm trying to make a login and register for the users with all different passwords and usernames.
Can someone please demonstrate or screenshot the code for how to do it? oh and I'm using xcode 4.6

Hemant Singh Rathore
  • 2,153
  • 1
  • 24
  • 38
anika
  • 73
  • 7

2 Answers2

1

Here can you find apple's KeyChainItemWrapper class: https://developer.apple.com/library/ios/samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_m.htm

You can use it like:

 KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"YourAppLogin" accessGroup:nil];

// Set the username and password using:
[keychainItem setObject:@"password you are saving" forKey:@"Password"];
[keychainItem setObject:@"username you are saving" forKey:@"Username"];

// Get them
 NSString *password = [keychainItem objectForKey:@"Password"];
 NSString *username = [keychainItem objectForKey:@"Username"];

// Delete them
[keychainItem resetKeychainItem];
0

NSUserDeafults store data within the app and Key-chain stores data in iOS keychain.
You can use SSKeyChain. It's use easy and works with both ARC and Non-ARC.

Also check this How to choose account and service values for SSKeychain

Community
  • 1
  • 1
Hemant Singh Rathore
  • 2,153
  • 1
  • 24
  • 38