简体   繁体   English

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

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

When I kill the app by swiping up in the multi-app UI in the simulator and relaunch it the application (didFinishLaunchingWithOptions) method is not called, and every time just the login screen shows up.当我通过在模拟器中的多应用程序 UI 中向上滑动来application (didFinishLaunchingWithOptions)并重新启动它时,不会调用application (didFinishLaunchingWithOptions)方法,并且每次只显示登录屏幕。 I do not understand what's going on and it really defeats the purpose of checking whether user is logged in or not from firebase if the method is not even called while launching the app again, would really appreciate some help!我不明白发生了什么,如果在再次启动应用程序时甚至没有调用该方法,它真的会破坏检查用户是否从 firebase 登录的目的,非常感谢一些帮助! (Does this have something to do with SceneDelegate methods I am seeing, from what i understand the didFinishLaunching method should be called regardless when launching an application) (这是否与我看到的 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
    } 

Here's the code for the MainViewController as requested这是请求的 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)
    }
}

The ---------appDelegate didFinishLaunchingWithOptions called!--------------- is printed only once, when the project is built and opened in simulator ---------appDelegate didFinishLaunchingWithOptions called!--------------- 只打印一次,当项目在模拟器中构建和打开时

Disclaimer: I'm very new in iOS app development.免责声明:我是 iOS 应用程序开发的新手。

The action of swiping up and killing the application breaks the debugger link.向上滑动并杀死应用程序的动作会破坏调试器链接。 So if you relaunch the application by clicking on the app itself in the simulator, you will no longer have a debugger link with Xcode.因此,如果您通过单击模拟器中的应用程序本身重新启动应用程序,您将不再拥有与 Xcode 的调试器链接。 That is the reason why you don't see the messages being printed anymore.这就是您看不到正在打印的消息的原因。

You have to relaunch from Xcode to get the launch messages printed once again.您必须从 Xcode 重新启动才能再次打印启动消息。

If you have other questions please post them separately.如果您有其他问题,请单独发布。 It will be easier to track and respond to by everyone.每个人都可以更轻松地跟踪和响应。

The problem is just the way you "relaunch in the sim".问题只是你“在模拟游戏中重新启动”的方式。 If you kill the app and then tap the app's icon in the simulator, you are no longer running in Xcode;如果你杀死应用程序,然后在模拟器中点击应用程序的图标,你将不再在 Xcode 中运行; you are running independently.你是独立运行的。 So you don't get any debugging any more;所以你不再进行任何调试; no print messages appear in the Xcode console, you don't stop at breakpoints, etc. Xcode 控制台中不会出现任何print消息,您不会在断点处停止,等等。

The solution is: relaunch by telling Xcode to build and run again, not by tapping the app's icon in the simulator.解决方案是:通过告诉 Xcode 重新构建并再次运行来重新启动,而不是通过点击模拟器中的应用程序图标来重新启动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 application:didFinishLaunchingWithOptions没有被调用 - application:didFinishLaunchingWithOptions is not being called - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 没有被触发 - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions was not triggered application:didFinishLaunchingWithOptions:在iPad上没有被调用 - application:didFinishLaunchingWithOptions: not getting called on iPad [UIApplication sharedApplication]和didFinishLaunchingWithOptions的应用程序参数之间有什么区别? - What's the difference between [UIApplication sharedApplication] and application argument of didFinishLaunchingWithOptions? URL方案:application:didFinishLaunchingWithOptions :,未调用handleOpenURL - URL schemes: application:didFinishLaunchingWithOptions:, handleOpenURL not called 远程通知“ application:didFinishLaunchingWithOptions:”方法未调用 - Remote Notification 'application:didFinishLaunchingWithOptions:' method not called 在什么情况下调用了application:didFinishLaunchingWithOptions :? - In what case that application:didFinishLaunchingWithOptions: been called? application:didFinishLaunchingWithOptions:在应用崩溃时被调用的方法 - application:didFinishLaunchingWithOptions: method getting called on app crash 未调用方法:-(void)应用程序:(UIApplication *)应用程序didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken - Method not being called: - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken 应用程序 openURL 在 didFinishLaunchingWithOptions 几秒钟后被调用 - Application openURL gets called a few seconds after didFinishLaunchingWithOptions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM