Swift Storyboard app launches to a black screen

Hi everyone,


I'm building a Swift app using Storyboards. I've been working fine for a few months now, but all of a sudden my app won't load properly. Whenever I open it on a Simulator or my physical iPhone, the launch screen is displayed before a black screen appears.

My Mac is on macOS Big Sur Developer Beta 5 with Xcode 12 Beta 6, and my iPhone is on iOS 14 Developer Beta 5.

This happened all of a sudden and I don't recall doing anything to cause it.

Here's what I've tried so far...

  • Renaming the storyboard and updating the target's General tab to the new name, as well as doing the same but manually editing Info.plist

  • Moving the storyboard in and out of "Copy Bundle Resources"

  • Updating to the latest Xcode 12 beta (I'm on macOS Big Sur)

  • Clearing Derived Data with DevCleaner

  • Starting a whole new project and moving all of my code and resources over via drag-and-drop (Interesting observation: when I started a new project, I added a simple label to the default Main.storyboard and ran it on my iPhone. The label wasn't displayed.

  • Adding a function to my AppDelegate to load the storyboard manually on launch

  • Adding various print statements in AppDelegate and my Home View Controller

AppDelegate

I've added
Code Block swift
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "Home")
self.window.rootViewController = initialViewController
self.window.makeKeyAndVisible()
print("App launched")

to my AppDelegate. Now, when I run my app, I get
printed. I also added
Code Block swift
override func viewDidLoad() {
super.viewDidLoad()
print("Home view loaded")

to my Home View Controller.
Now, when I run my app, I get this printed in Xcode:
Code Block text
2020-08-28 13:11:20.140963+0100 MY-APP[11077:1951343] libMobileGestalt MobileGestaltCache.c:166: Cache loaded with 4536 pre-cached in CacheData and 53 items in CacheExtra.
2020-08-28 13:11:20.759943+0100 MY-APP[11077:1951162] Metal API Validation Enabled
Home view loaded
App launched


Still, nothing on my iPhone. The launch screen appears, fades to black, and that's it. I'm so confused.

If anyone knows how to fix this, or something I can try, please let me know. Thank you in advance!

Have you a scene delegate ? You should.
I do:
Code Block Swift
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let _ = (scene as? UIWindowScene) else { return }
    }
    func sceneDidDisconnect(_ scene: UIScene) {
    }
    func sceneDidBecomeActive(_ scene: UIScene) {
    }
    func sceneWillResignActive(_ scene: UIScene) {
    }
    func sceneWillEnterForeground(_ scene: UIScene) {
    }
    func sceneDidEnterBackground(_ scene: UIScene) {
    }
}

Thanks for your help.

New try.

Did you remove the declaration

Code Block
    var window: UIWindow?


from AppDelegate ?
I did have that removed for some reason, but even after adding it my app still launches to a black screen.

To clarify, here's my AppDelegate:
Code Block Swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
    }
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    }    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print(url)
        return true
    }
}

And here's my SceneDelegate:

Code Block Swift
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    }
    func sceneDidDisconnect(_ scene: UIScene) {
    }
    func sceneDidBecomeActive(_ scene: UIScene) {
    }
    func sceneWillResignActive(_ scene: UIScene) {
    }
    func sceneWillEnterForeground(_ scene: UIScene) {
    }
    func sceneDidEnterBackground(_ scene: UIScene) {
    }
}


Thanks again for your help.
Check your info.plist

Have you an Application Scene Manifest ?

Here is what it looks like (I had to edit the url with a few spaces to remove)

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http: //www.apple. com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
</plist>

What is the deployment target? If it is iOS 12.4.8 or earlier, add this to the AppDelegate class:
Code Block swift
var window: UIWindow?

I have Xcode 12 beta 3 and I have never seen this issue!
Swift Storyboard app launches to a black screen
 
 
Q