简体   繁体   English

在用户首次打开应用程序时处理登录屏幕的最佳方法是什么?

[英]What's the best way to handle showing a sign in screen the first time a user opens an app?

I'm building an iOS app at the moment and trying to work out the best way to present the necessary screens. 目前,我正在构建一个iOS应用,并尝试找出呈现必要屏幕的最佳方法。

The app is a tab-based app but the tabbar and it's children should not be visible until after the user has signed in. 该应用程序是基于标签的应用程序,但在用户登录后,该标签栏及其子级才应该可见。

Currently, the app delegate sets the tabbarcontroller as the root view controller when application:didFinishLaunchingWithOptions is called and then the first controller in the tab bar controller presents the sign in view controller if required. 当前,在调用application:didFinishLaunchingWithOptions时, application:didFinishLaunchingWithOptions程序委托将tabbarcontroller设置为根视图控制器,然后,如果需要,选项卡栏控制器中的第一个控制器将显示登录视图控制器。

The problem I have with this approach is that the first view controller in the tab bar is very busy. 这种方法的问题在于选项卡栏中的第一个视图控制器非常忙。 It makes a few requests to external APIs, some of which require a valid session token first. 它向外部API发出一些请求,其中一些请求首先需要有效的会话令牌。

What I'd like to do, unless someone can suggest a better solution, is to check in application:didFinishLaunchingWithOptions whether there's a valid session ID or not. 除非有人可以提出更好的解决方案,否则我想做的是检查application:didFinishLaunchingWithOptions是否存在有效的会话ID。 If there is, set the tabBarController as the rootViewController, if there's not, set the sign in controller as the root view controller. 如果存在,则将tabBarController设置为rootViewController;如果没有,则将登录控制器设置为根视图控制器。

can anyone see any pitfalls in this idea? 有人能看到这个想法有什么陷阱吗?

Use NSUserDefault for storing bool value which will be true first time and login screen will appear along with make bool value to false. 使用NSUserDefault来存储布尔值,这将是第一次,登录屏幕将与make bool value一起显示为false。 So second login scrren will not appear 因此不会出现第二个登录屏幕

Add this in application:didFinishLaunchingWithOptions method: 将此添加到application:didFinishLaunchingWithOptions方法中:

 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstTime"];
 [[NSUserDefaults standardUserDefaults] synchronize];

Now 现在

 if([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstTime"] == YES)
 {
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"FirstTime"];
    [[NSUserDefaults standardUserDefaults] synchronize];
   //login screen
 } 

I've used both approaches in my apps and the first one you've described is the best one since you won't need to mess up with changing your view controllers hierarchy. 我已经在我的应用程序中使用了这两种方法,而您所描述的第一种方法是最好的方法,因为您无需弄乱更改视图控制器层次结构。 You really should have a boolean value stored in NSUserDefaults and another boolean value in your first view controller. 您确实应该在NSUserDefaults中存储一个布尔值,并在第一个视图控制器中存储另一个布尔值。 Check the userDefault bool value in your tabbar's first view controller's viewDidLoad method to see if user is authenticated, if he's not, set the first view controller's bool value to appropriate value and do not perform the actions that you are required to perform via third party APIs, authenticate, set the bool to appropriate value and go back to the third party APIs. 检查选项卡的第一个视图控制器的viewDidLoad方法中的userDefault bool值,以查看用户是否已通过身份验证;如果未通过身份验证,则将第一个视图控制器的bool值设置为适当的值,并且不执行您需要通过第三方API执行的操作,进行身份验证,将布尔值设置为适当的值,然后返回第三方API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 首次启动应用程序时看电影的最佳方法是什么 - What is the best way to start a movie the first time your app starts 转换iPad应用程序以处理两种视图模式的最佳方法是什么? - What's the best way to convert iPad app to handle both view modes? 备份用户应用数据的最佳方式 - Best way to backUp user's app data 应用程序第一次打开时加载尝试 - Loading trie first time the app opens 从iPhone应用程序-> PHP-> MySQL保护用户密码的最佳方法是什么? - What is the best way to go about protecting a user's password going from iPhone app -> PHP -> MySQL? 如何使WSCoachMarksView演练仅在用户首次打开应用程序时运行? - How to make WSCoachMarksView walkthrough only run the first time user opens app? 自应用程序启动以来第一次确定方法内部是否是最简单的方法? - What's the easiest way to determine inside a method if it has been called the first time since app start? 在iPhone上找到用户的Documents目录的最佳方法是什么? - What's the best way to find the user's Documents directory on an iPhone? 如果是首次使用该应用,则显示其他导航控制器 - Showing a different navigation controller if it's the first time using the app 向用户展示加载iPhone的最佳方式是什么? - What's the best way to show the user something is loading on the iPhone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM