September 20, 2019
I've encountered this bug enough times that I figured it was time to write a quick post about it. If you've looked into multiple window support for your app in iOS 13, you might know that a lot of the setup you used to have to do in the app delegate now lives in the scene delegate instead.
However, multiple times now, I've thought I've set everything up correctly (scene delegate class implemented, configuration with delegateClass
set properly, correct Info.plist setup, etc), only to get a black screen on launch.
The secret is this: prior to iOS 13, it was common to set up your UIWindow
with the bounds of the screen:
// Does not work in iOS 13+
window = UIWindow(frame: UIScreen.main.bounds)
This breaks when using the UISceneSession system. Instead, you have to initialize the window with the scene itself, in your scene(scene:willConnectTo:options:)
method:
window = UIWindow(windowScene: windowScene)
This has generally been the missing piece I forgot, and ends up resolving the black screen issue. Here's a concrete example.
I'm Noah, a software developer based in the San Francisco Bay Area. I focus mainly on full stack web and iOS development