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

前端 未结 14 1154
独厮守ぢ
独厮守ぢ 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:30

    I looked at using KeychainItemWrapper (the ARC version) but I didn't find its Objective C wrapper as wholesome as desired.

    I used this solution by Kishikawa Katsumi, which meant I wrote less code and didn't have to use casts to store NSString values.

    Two examples of storing:

    [UICKeyChainStore setString:@"kishikawakatsumi" forKey:@"username"];
    [UICKeyChainStore setString:@"P455_w0rd$1$G$Z$" forKey:@"password"];
    

    Two examples of retrieving

    UICKeyChainStore *store = [UICKeyChainStore keyChainStore];
        // or
    UICKeyChainStore *store = [UICKeyChainStore keyChainStoreWithService:@"YOUR_SERVICE"];
    
    NSString *username = [store stringForKey:@"username"];
    NSString *password = [store stringForKey:@"password"];
    

提交回复
热议问题