gpt4 book ai didi

ios - iOS Swift Firebase在应用启动时检查用户不起作用

转载 作者:行者123 更新时间:2023-12-01 15:56:58 25 4
gpt4 key购买 nike

我用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 }
}

最佳答案

iOS 13中引入了SceneDelegate。对于iOS 12及以下版本,应在AppDelegatedidFinishLaunchingWithOptions方法中实现相同的逻辑,如下所示:

@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
}
}

关于ios - iOS Swift Firebase在应用启动时检查用户不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62354340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com