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

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

    There is a small bug in the above code (by the way Dave it was very helpful your post thank you)

    In the part where we save the credentials it also needs the following code in order to work properly.

    [self.keychainItem setObject:@"myCredentials" forKey:(__bridge id)(kSecAttrService)];
    

    most probably is because the second time we try to (re-)sign in with the same credentials it finds them already assigned in the keychain items and the app crashes. with the above code it works like a charm.

    0 讨论(0)
  • 2020-11-22 06:50

    If you are having an issue retrieving the password using the keychain wrapper, use this code:

    NSData *pass =[keychain objectForKey:(__bridge id)(kSecValueData)];
    NSString *passworddecoded = [[NSString alloc] initWithData:pass
                                               encoding:NSUTF8StringEncoding];
    
    0 讨论(0)
提交回复
热议问题