[application(_ application:UIApplication,didFinishLaunchingWithOptions)在启动时未调用

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

免责声明:我是iOS应用开发的新手。

我的目标是如果firebase auth告诉我该用户尚未登录,并且如果他已登录,我希望将其发送到登录屏幕,我想将其发送到主屏幕。我在MainViewController(也链接到仅具有应用程序徽标的情节提要)中进行路由。当我通过在模拟器中的多应用程序UI中向上滑动杀死应用程序并重新启动它时,不会调用application (didFinishLaunchingWithOptions)方法,并且每次都会显示登录屏幕。我不明白发生了什么,如果再次启动应用程序时甚至没有调用该方法,这真的无法达到检查用户是否从firebase登录的目的,将不胜感激! (这与我所看到的SceneDelegate方法有关吗,据我了解,无论启动应用程序时,都应调用didFinishLaunching方法)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        print("---------appDelegate didFinishLaunchingWithOptions called!---------------")
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        window?.rootViewController = MainViewController()
        FirebaseApp.configure()
        return true
    } 

这里是所请求的MainViewController的代码

import UIKit
import Firebase

class MainViewController: UIViewController {

    var handle: AuthStateDidChangeListenerHandle?

    override func viewDidLoad() {
        super.viewDidLoad()
        DispatchQueue.main.async {
            self.handle = Auth.auth().addStateDidChangeListener { (auth, user) in
                if user == nil {
                    print("nil user -----------")
                    self.perform(#selector(self.showHomeController), with: nil, afterDelay: 3)
              } else {
                    print("non nil user --------")
                    self.perform(#selector(self.showWelcomeController), with: nil, afterDelay: 3)
              }
            }
        }
    }

    @objc func showWelcomeController () {
        present(WelcomeViewController(), animated: true, completion: nil)
    }

    @objc func showHomeController () {
        present(HomeViewController(), animated: true, completion: nil)
    }


}

[------------ appDelegate didFinishLaunchingWithOptions称为!---------------当在模拟器中构建并打开项目时,仅打印一次

ios swift xcode appdelegate launching-application
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.