我的登录屏幕嵌入在中UINavigationController
,我的主页屏幕嵌入在中UITabBarController
。
我的登录页面是通过编程方式完成的,并且TabBarController
是使用创建的storyboards
。在AppDelegate.swift
文件中,我将登录屏幕设置为rootViewController
。
但现在我要检查,如果用户登录,使TabBarController
的rootViewController
,如果用户没有,重定向到登录界面登录,然后Segue公司的TabBarController
并使其成为rootViewController
。
服务器通过向客户端发送令牌来认证用户。我是否使用来存储令牌NSUserDefaults
?我是否应该检查用户是否具有_token
_作为验证用户是否已登录的方法?
由于您要创建您的LoginViewController
编程,所以我假定TabBarController
将是rootViewController
的storyboard
默认。您需要做的AppDelegate
就是这个。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let token = UserDefaults.standard.object(forKey: "token")
if token == nil {
//***************
//Create your LoginViewController and make it the rootViewController
//***************
}
return true
}
注意:我正在使用,Swift 3
因此语法会有细微的差别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句