Save value in keychain - iOS application

Login and sign up activity is very common in every ios application. Most of the applications follow single sign in process. Single sign in means user have to login only once. Generally developers tend to save values(username, password) in user default. When user delete the application, the values stored in the NSUserDefault also vanishes, then user have to sign in again.

Alternative to NSUserDefault, which save values permanently in keychain:-

  1. Grab the four files (.h and .m) PDKeychainBindingsController folder and add them to your xCode project.
  2. Import the header file. #import "PDKeychainBindings.h"

Set object:-
        [[PDKeychainBindings sharedKeychainBindings] setObject:@"Pardeep" forKey:@"key_name"];

Get object from key:-

            NSString *folderPath=[[PDKeychainBindings sharedKeychainBindings] objectForKey:@"key_name"];

Remove object:
            [[PDKeychainBindings sharedKeychainBindings] removeObjectForKey:@"key_name"];


  • If you are getting any keychain access error or SecItemAdd and SecItemCopyMatching returns error code -34018, then follow this answer:-
  • keychain API only work with Strings


Popular posts from this blog

Play youtube video in iOS app

Disabling print for Production In Swift Project