Friday, November 30, 2012

How to store values in keychain of ios

How to store values in keychain of ios

Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

Tutorial for: Key chain, user defaults, values, KeychainItemWrapper, iphone, ios

What is keyChain -

Key chain is the place where we can store the values which will be retain even after deleting application. Generally we store username and password in it.

Difference between KeyChain and userDefaults
The values which are store in userDeafults are deleted when we delete the app from our device but the values stored in KeyChain will not.

Apple provides helper classes, for that you can refer to this link
Or you can download it from here

Initialise the class

KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"Your application name" accessGroup:nil];

How to save the values
[wrapper setObject:@"PASSWORD" forKey:@"KEYPASS"];
[wrapper setObject:@"USERNAME" forKey:@"KEYUSER"];

how to retrive the values

NSString *pwd = [wrapper objectForKey:@"KEYPASS"];
NSString *user = [wrapperobjectForKey:@"KEYUSER"];

How to delete the values

[wrapper resetKeychainItem];



  1. I did not working for me.. :(

  2. I've got as far as adding the KeychainItemWrapper class. When I add KeychainItemWrapper.m into my project I get al lsorts of error about incompatible pointer types.

    Project is targeting iOS 6.

  3. That's interesting! Can you please share more about it? Thank you.

    Hire iPhone Developer & Android App Development

  4. Yeah this code seems to be really outdated.. lots of release statements. It's annoying that apple doesn't update it. Lot's of errors, some asking me to insert (__bridge) statements, others saying incompatible pointer types..

    I found this code ( which has no errors (for me) but I can't figure out how to make it work still... when I call something like [wrapper setObject:@"USERNAME" forKey:@"KEYUSER"];

    it doesn't work...

  5. Thank you for your guide to with upgrade information.
    iOS Online Training Bangalore

  6. Data Science Certification Courses in Hyderabad. ExcelR is the Best Data Science Training Institute in Hyderabad with Placement assistance and offers a blended.