SwiftUI iPad app shows black screen on enabling multiple window support

只谈情不闲聊 提交于 2020-05-31 06:36:11

问题


Using SwiftUI on macOS Catalina, when enabling "Support multiple windows", my iPad app shows a black screen on launch in the simulator

I'm using the stock SwiftUI project, with the only change being clicking the "Support multiple windows" checkbox

This is from my SceneDelegate, which I believe is the proper way to set up a window in SwiftUI

var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()
}

In my Info.plist I believe I have everything I need

<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <true/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UILaunchStoryboardName</key>
                    <string>LaunchScreen</string>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                </dict>
            </array>
        </dict>
    </dict>

回答1:


The window must be initialized as

let window = UIWindow(windowScene: scene as! UIWindowScene)


来源:https://stackoverflow.com/questions/56843499/swiftui-ipad-app-shows-black-screen-on-enabling-multiple-window-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!