如何:调试 UIWindows 是在初始应用程序激活之前创建的

How to : Debug UIWindows were created prior to initial application activation

我的控制台今天发布了这个错误,[ApplicationLifecycle] UIWindows were created prior to initial application activation. This may result in incorrect visual appearance.

这导致应用程序 UI 无法正常运行。我以前从未见过这个,需要了解从哪里开始调试。

macOS: Catalina 10.15
XCode version: Version 11.1 

我认为 apps main UIWindow 应该延迟启动。试试这个:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    lazy var window: UIWindow? = UIWindow(frame: UIScreen.main.bounds)

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window?.rootViewController = RootViewController() // root view controller
        window?.makeKeyAndVisible()

        return true
    }
}