0

I have the following code:

NSData *secret = [pssword dataUsingEncoding:NSUTF8StringEncoding];
    query =@{
             (__bridge id)kSecClass:(__bridge id) kSecClassGenericPassword,
             (__bridge id)kSecAttrService:@"My App",
             (__bridge id)kSecAttrAccount:usrid,
             (__bridge id)kSecValueData:secret
             };

    OSStatus status = SecItemAdd((__bridge CFDictionaryRef) query, NULL);

    if(status != errSecSuccess)
    {
         NSLog(@"Unable add item with key =%@ error:%ld",secret,status);
    }

It seem that the password and userid, is only saved for the session. Every time I refresh the simulator or re-launch the application the password and userid disappear / gone for good.

How do I save them to the keychain DB permanently please?

Thank you

1 Answers1

1

You can use NSUserDefaults to do that simply
To Save data use when you have the password (for example if the password is NSString)

     NSString*userIDString=@"myPassordStringXXX";
     [[NSUserDefaults standardUserDefaults] setObject:userIDString forKey:@"passwordKey"];
     [[NSUserDefaults standardUserDefaults] synchronize];

To retrive the data you can use

NSString*passwordString=[[NSUserDefaults standardUserDefaults] objectForKey:@"passwordKey"]
Adel
  • 648
  • 1
  • 9
  • 26