iOS: How to store username/password within an app?

前端 未结 14 1182
独厮守ぢ
独厮守ぢ 2020-11-22 06:18

I have a login-screen in my iOS app. The username and password will be saved in the NSUserDefaults and be loaded into the login-screen again when you enter the

14条回答
  •  臣服心动
    2020-11-22 06:31

    A very easy solution via Keychains.

    It's a simple wrapper for the system Keychain. Just add the SSKeychain.h, SSKeychain.m, SSKeychainQuery.h and SSKeychainQuery.m files to your project and add the Security.framework to your target.

    To save a password:

    [SSKeychain setPassword:@"AnyPassword" forService:@"AnyService" account:@"AnyUser"]
    

    To retrieve a password:

    NSString *password = [SSKeychain passwordForService:@"AnyService" account:@"AnyUser"];
    

    Where setPassword is what value you want saved and forService is what variable you want it saved under and account is for what user/object the password and any other info is for.

提交回复
热议问题