iOS Swift Firebase 在应用程序启动时检查用户不工作
iOS Swift Firebase Checking user at app startup not working
我用 firebase 开发了一个应用程序。该应用程序检查 sceneDelegate.swift 文件中是否有任何用户在每次启动时登录。但它只适用于 iOS 13 台设备。 iOS 12台设备用户每次都要登录。我该如何解决这个问题?谢谢
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@available(iOS 13.0, *)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let navigationController = board.instantiateViewController(identifier: "navigationController") as! UINavigationController
window?.rootViewController = navigationController
}
guard let _ = (scene as? UIWindowScene) else { return }
}
SceneDelegate 是在 iOS 13 中引入的。对于 iOS 12 及以下版本,您应该在 AppDelegate
的 didFinishLaunchingWithOptions
方法中实现相同的逻辑,如下所示:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.makeKeyAndVisible()
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let navigationController = board.instantiateViewController(withIdentifier: "navigationController") as! UINavigationController
window?.rootViewController = navigationController
}
return true
}
}
我用 firebase 开发了一个应用程序。该应用程序检查 sceneDelegate.swift 文件中是否有任何用户在每次启动时登录。但它只适用于 iOS 13 台设备。 iOS 12台设备用户每次都要登录。我该如何解决这个问题?谢谢
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@available(iOS 13.0, *)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let navigationController = board.instantiateViewController(identifier: "navigationController") as! UINavigationController
window?.rootViewController = navigationController
}
guard let _ = (scene as? UIWindowScene) else { return }
}
SceneDelegate 是在 iOS 13 中引入的。对于 iOS 12 及以下版本,您应该在 AppDelegate
的 didFinishLaunchingWithOptions
方法中实现相同的逻辑,如下所示:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.makeKeyAndVisible()
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let navigationController = board.instantiateViewController(withIdentifier: "navigationController") as! UINavigationController
window?.rootViewController = navigationController
}
return true
}
}