在 AppDelegate 中推送时不显示新 ViewController

new ViewController is not displaying when pushed in AppDelegate

这是我的代码,用于在 swift 5 中显示来自应用程序委托的 ViewController,我所做的一切都与其他人相同但是当应用程序时未显示新的 ViewController已启动。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let welcome  = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen

        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = welcome
        self.window?.makeKeyAndVisible()
 return true
}

放入

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let welcome  = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = welcome
        self.window?.makeKeyAndVisible()

        return true 
}

更新: 如果它不工作尝试:

 if let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main){
      if let welcome  = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen{
           //Does it come here?
           self.window = UIWindow(frame: UIScreen.main.bounds)
           self.window?.rootViewController = welcome
           self.window?.makeKeyAndVisible()        
     }
 }

如果最内部的 ifif let welcome = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen

,请确保您确实进入了 body