Firebase用户已登录Swift / xcode / ios Keep

问题描述 投票:0回答:1

我使用firebase进行了用户登录,但效果很好...除非它不能使用户保持登录状态。我尝试查看教程,但它们均已过时,不能使用的当前语法迅速。有人可以帮助我,告诉我该怎么做或添加什么代码。不胜感激!

ios swift firebase firebase-authentication signing
1个回答
0
投票

要使用户保持登录状态,请在SceneDelegate内部检查当前用户是否存在。如果当前用户存在,则他们已登录,因此将根视图控制器设置为主视图控制器。如果不存在当前用户,则他们没有登录,因此请使根视图控制器成为登录视图控制器。

guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: UIScreen.main.bounds)

if let _ = Auth.auth().currentUser {
    window?.rootViewController = HomeViewController()
    window?.makeKeyAndVisible()
    window?.windowScene = windowScene
} else {
    window?.rootViewController = SignInViewController()
    window?.makeKeyAndVisible()
    window?.windowScene = windowScene
}

还要确保您实现了允许用户退出应用程序的功能。请参阅有关如何在Firebase中管理用户的更多文档。

https://firebase.google.com/docs/auth/ios/manage-usershttps://firebase.google.com/docs/auth/ios/password-auth

© www.soinside.com 2019 - 2024. All rights reserved.