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

application(_ application: UIApplication, didFinishLaunchingWithOptions) not called on start up

当我通过在模拟器中的多应用程序 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 应用程序开发的新手。

向上滑动并杀死应用程序的操作破坏了调试器link。因此,如果您通过在模拟器中单击应用程序本身来重新启动应用程序,您将不再有调试器 link 和 Xcode。这就是为什么您不再看到正在打印的消息的原因。

您必须从 Xcode 重新启动才能再次打印启动消息。

如果您有其他问题,请单独 post。更容易被大家追踪和回复。

问题出在你的方式上"relaunch in the sim"。如果您终止该应用程序,然后在模拟器中点击该应用程序的图标,您将不再 运行ning in Xcode;你 运行 独立。所以你不会再得到 any 调试;没有 print 消息出现在 Xcode 控制台中,您不会在断点处停止等

解决方案是:通过告诉 Xcode 构建并再次 运行 重新启动,而不是通过在模拟器中点击应用程序的图标。