问题
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