使用Xcode11 beta版新建的SwiftUI项目运行黑屏问题

在Xcode11未发布正式版前,使用beta版新建的项目,在现在正式版后,运行项目一直黑屏,无法正常运行,经排查出现问题在于SceneDelegate中

beta版本时生成的代码:


funcscene(_scene:UIScene, willConnectTo session:UISceneSession, options connectionOptions:UIScene.ConnectionOptions) {

        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.

        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.

        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        // Use a UIHostingController as window root view controller

        letwindow =UIWindow(frame:UIScreen.main.bounds)

        window.backgroundColor = UIColor.white

        window.rootViewController = UIHostingController(rootView: LandmarkList())

        self.window= window

        window.makeKeyAndVisible()

    }

修改为:


funcscene(_scene:UIScene, willConnectTo session:UISceneSession, options connectionOptions:UIScene.ConnectionOptions) {

        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.

        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.

        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        // Use a UIHostingController as window root view controller

        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: LandmarkList())
            self.window = window
            window.makeKeyAndVisible()
        }

    }

你可能感兴趣的:(使用Xcode11 beta版新建的SwiftUI项目运行黑屏问题)