Search code examples
iosnsuserdefaultskeychain

How to save username and password in an app so that we do not need to login the app?


I am new to iOS i donot know how to save username and password in an app So that there is no need to fill login details in the app till then user do not logout the app. I save my username and password in NSUSerdefaults. I search on google. I found this could be done with KeyChainWrapper class . i tried that way but that will not give me useful result. AnyOne can me help out for this problem.He/She could be greatly appreciate for that.


Solution

  • Use the class NSUserDefaults

    [[NSUserDefaults standardUserDefaults] setObject:@"username" forKey:@"usersave"];
    [[NSUserDefaults standardUserDefaults] setObject:@"usernamexxx" forKey:@"passsave"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    

    Get them using:

    NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"passsave"];
    NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:@"usersave"];