![](/img/trans.png)
[英]application:didFinishLaunchingWithOptions is not being called
[英]application(_ application: UIApplication, didFinishLaunchingWithOptions) not called on start up
當我通過在模擬器中的多應用程序 UI 中向上滑動來application (didFinishLaunchingWithOptions)
並重新啟動它時,不會調用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 called!--------------- 只打印一次,當項目在模擬器中構建和打開時
免責聲明:我是 iOS 應用程序開發的新手。
向上滑動並殺死應用程序的動作會破壞調試器鏈接。 因此,如果您通過單擊模擬器中的應用程序本身重新啟動應用程序,您將不再擁有與 Xcode 的調試器鏈接。 這就是您看不到正在打印的消息的原因。
您必須從 Xcode 重新啟動才能再次打印啟動消息。
如果您有其他問題,請單獨發布。 每個人都可以更輕松地跟蹤和響應。
問題只是你“在模擬游戲中重新啟動”的方式。 如果你殺死應用程序,然后在模擬器中點擊應用程序的圖標,你將不再在 Xcode 中運行; 你是獨立運行的。 所以你不再進行任何調試; Xcode 控制台中不會出現任何print
消息,您不會在斷點處停止,等等。
解決方案是:通過告訴 Xcode 重新構建並再次運行來重新啟動,而不是通過點擊模擬器中的應用程序圖標來重新啟動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.