我可能已经在Matt Neuburg的书“编程iOS 13”的书中找到了解决方案 安德烈班克罗夫特的页面. He writes that as of iOS 13 the app is launched with window scene support, which alters the order of assignments and, most importantly, the call to
(_:didFinishLaunchingWithOptions:). I’ll quote here:
UIApplicationMain proceeds depends on what it discovers as it gets going. New in iOS 13, your app can use scenes and scene-related classes and protocols (UISceneSession, UIScene, UIWindowScene, UIWindowSceneDelegate).”
UIApplicationMain looks to see whether your app uses a main storyboard; if so, it instantiates the storyboard’s first view controller (that would be your
UITabBarController I presume).
UIApplicationMain assigns the window (of type
UIWindow) to the app delegate’s
This would be all well and good for your code, as the root view controller already exists when
(_:didFinishLaunchingWithOptions:) is called. However, in iOS 13 the order changes to the following:
After creating the application instance and assigning the app delegate class to its delegate property (I omitted that very first step above),
UIApplicationMain immediately calls
(_:didFinishLaunchingWithOptions:). This is problematic for your code because, at this point, not even a window exists yet and thus your force unwrap crashes the app.
Lastly, it calls
(_:willConnectTo:options:) in the
Long story short, your code refers to something that does not exist at this point of time in the launching process. The fix would be to move your code over to the
(_:willConnectTo:options:)method, which is called at the same point in time when
(_:didFinishLaunchingWithOptions:) used to be called. Hope that helps.