iPhone会话登录帮助 [英] help with iphone session login

查看:42
本文介绍了iPhone会话登录帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在许多应用程序中,您只需登录一次应用程序,然后在下次打开该应用程序时,无需再次输入用户名和密码.如何在SFHFKeychainUtils的帮助下完成此操作?

I see in many apps that you only need to login to an app once and then the next time you open the app, you don't need to input the username and password again. How can I do this with the help of SFHFKeychainUtils?

推荐答案

您已经回答了几乎所有的问题.您可以使用SFHFKeychainUtils包装器将凭据存储在应用程序的钥匙串中.当应用程序加载时,它将检查是否有密码.如果不是,请提示用户登录并存储用户名&相应的密码.

You pretty much answered your question already. You can store credentials in the application's Keychain using the SFHFKeychainUtils wrapper. When the application loads, it checks to see if there is a password. If not, prompt the user to login and store the username & password accordingly.

// Application Loads... 

NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSString *username = [standardDefaults stringForKey:@"kApplicationUserNameKey"];

if (username) {
    NSError *error = nil;
    NSString *password = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:@"com.company.app" error:&error];

    // Check password...
} else {
    // No username. Prompt the user to enter username & password and store it
    username = @"userEnteredUsername";
    NSString *password = @"userEnteredPassword";

    [standardDefaults setString:username forKey:@"kApplicationUserName"];
    NSError *error = nil;
    BOOL storeResult = [SFHFKeychainUtils storeUsername:username andPassword:password forServiceName:@"com.company.app" updateExisting:YES error:&error];
}

这显然是不完整的,并且没有适当的组织方式,但是您应该能够理解基本流程.

This is obviously incomplete and not organized in the appropriate fashion but you should be able to understand the basic flow.

这篇关于iPhone会话登录帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆