Reputation: 349
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.
I've added
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
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:
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!Upvotes: 4
Views: 3635
Reputation: 21
I also faced the same issue. The original question says,
"This happened all of a sudden and I don't recall doing anything to cause it."
This is exactly what happened to me and following is how I solved the issue.
In Main.storyboard, there is an entry point to the app which is visually depicted as an arrow pointing to the Navigation Controller. Once the issue showed up, I noticed that this arrow is now somehow missing and Is Initial View Controller checkbox in the View Controller section of the Attribute Inspector tab in the Inspectors pane is now unchecked.
The issue was resolved when I checked the Is Initial View Controller checkbox mentioned above(The arrow in the storyboard navigation controller also reappeared upon checking this). Below is an image of xcode after solving the issue to help get a better understanding.
This is an image showing the Navigation Controller and Inspectors pane after the issue was fixed.
Upvotes: 0
Reputation: 139
If you don't want to switch to the Scene API just yet, you can also just set UIApplicationSupportsMultipleScenes
to NO
in the UIApplicationSceneManifest
section which probably recently appeared in your Info.plist. That's what I just did, and it fixed the issue for me.
Upvotes: 2
Reputation: 765
Make sure there a window like this present in your sceneDelegate and AppDelegate both.
class AppDelegate: UIResponder, UIApplicationDelegate {
// check for this
var window: UIWindow?
// check for this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
}
}
Upvotes: 2
Reputation: 1162
In latest version, window property is no more available in AppDelegate. Now, it is moved to SceneDelegate.swift . You can try doing as below in func scene willConnectTo:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
if let windowScene = scene as? UIWindowScene {
self.window = UIWindow(windowScene: windowScene)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyBoard.instantiateViewController(withIdentifier: "Home")
self.window?.rootViewController = initialViewController
self.window!.makeKeyAndVisible()
}
}
Update: Also make your Main Interface under General menu is empty
Also you have to remove the <key>UIMainStoryboardFile</key><string>Main</string>
and <key>UISceneStoryboardFile</key> <string>Main</string>
from your Info.plist
of your project.
Upvotes: 1