Xcode iOS:检查用户是否已登录并显示不同的视图 [英] Xcode iOS: check if user is logged in and show different views if not

查看:139
本文介绍了Xcode iOS:检查用户是否已登录并显示不同的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,其中登录用户比未登录用户有更多功能。基本上,我有或多或少5个标签。当我启动应用程序时,用户立即获得登录页面。他可以决定跳过它。如果他跳过它,那么他只会有3个标签。如果他成功登录,则会有5个。

I'm coding an app where a logged in user has got a couple of extra functionalities than a non logged in user. Basically, I have more or less 5 tabs. When I launch the app, the user immediately gets the login page. He can decide to skip it. If he skips it, there'll only be 3 tabs for him. If he logs in successfully, there'll be 5.

我已经创建了登录页面。如果用户登录正确,我只是不知道如何存储会话,如果用户没有,则只显示一定数量的选项卡。我来自PHP,我刚刚开始学习Objective-C,所以我在PHP中寻找与$ _SESSION相同的东西,或多或少。

I already have my login page made. I just don't know how I can store a session if the user is logged in correctly, and only display a certain number of tabs if the user isn't. I come from PHP, I've just started learning Objective-C, so I'm looking for the same thing as $_SESSION in PHP, more or less.

所以:如果用户登录,存储会话并显示所有选项卡。如果他没有,只显示有限数量的标签。
我该如何处理?

So: if user logs in, store session, and show all the tabs. If he doesn't, only show a limited number of tabs. How should I approach this?

推荐答案

在存储会话方面,我假设用户名和密码就足够了。

In terms of storing the session, I assume username and password is enough.

如果您使用的话,可以在NSUserDefaults或CoreData中存储用户名。使用钥匙串最好存储密码。 SSKeychain 可以轻松完成此任务。

You could store the username as you wish in NSUserDefaults or CoreData if you are using it. Storing a password is best using the keychain. SSKeychain makes it easy to do this.

[SSKeychain setPassword:password forService:myAppName account:userName]

您可以存储他们在内存中登录的事实,但是在应用程序重新启动时检查:

You could store the fact they are logged in in-memory, but on app relaunch check by:

NSString *password = [SSKeychain passwordForService:myAppName account:userName];
if (password != nil)
{
    // Logged in
}

如果用户退出,轻松删除钥匙串中的密码

If the user logs out, easy as deleting the password from the keychain by

[SSKeychain deletePasswordForService:myAppName account:userName]

这篇关于Xcode iOS:检查用户是否已登录并显示不同的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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