【发布时间】:2019-02-04 06:19:12
【问题描述】:
我已经在应用程序委托中实现了 Firebase Auth 和 Firebase 数据库,它检查用户是否登录。它检查数据库中的“用户”节点以查看子快照中是否有用户 ID,以及此操作大约需要 2-3 秒。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
if let uid = Auth.auth().currentUser?.uid {
Database.database().reference().child("users").child(uid).observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("App Delegate: User found!")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Main")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
}
else{
print("App Delegate: User not found!")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Login")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
}
})
}
return true
}
登录视图控制器是初始视图控制器。当启动屏幕淡出时,显示登录视图控制器,如果用户登录,则显示主视图控制器,但在这种情况下,显示登录视图控制器的时间间隔为 2-3 秒。 我也尝试实现 NavigationController 但同样的问题。
那么,如果用户已登录并直接进入主视图控制器并有效管理 2-3 秒的时间间隔,我怎么能不显示登录视图控制器。
【问题讨论】:
标签: ios swift firebase firebase-realtime-database firebase-authentication