14

I have a SwiftUI/SpriteKit project. In an error-laden quest to change the bundle identifier, I decided to create a new project and copy my files over.

Now I've got this new project with all my old files but when I run it, I get a blank screen because my SceneDelegate function scene(_:willConnectTo:options:) is not being called.

According to the documentation, a SceneDelegate setup will work if you make the appropriate changes to your info.plist. However, I've made those changes, and my SceneDelegate remains inoperative.

In my info.plist, I have the following: enter image description here

Here's the relevant part of my SceneDelegate:

import UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? static var mainData = MainData() func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). // Create the SwiftUI view that provides the window contents. let contentView = ContentView() // Use a UIHostingController as window root view controller. if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: contentView.environmentObject(SceneDelegate.mainData)) self.window = window window.makeKeyAndVisible() } } //...more stuff here } 

Question: Why isn't my SceneDelegate working? What am I doing wrong?

Thank you!

4
  • what you get in debugger window while launching app? Commented May 3, 2021 at 13:01
  • Are you migrating from AppDelegate or the new App lifecycle? Commented May 3, 2021 at 14:34
  • @RB's I get nothing in the logs, actually. Commented May 3, 2021 at 14:43
  • @aheze Migrating from AppDelegate Commented May 3, 2021 at 14:44

1 Answer 1

55

I have no idea why my SceneDelegate wasn't working, but I did two things:

  1. Deleted the app from the simulator I was using.
  2. Restarted Xcode.

My SceneDelegate now works as expected.

Sign up to request clarification or add additional context in comments.

4 Comments

wow - restarting XCode did the trick ... sigh
Thank you for this, I was going crazy why it's not working. Xcode is being Xcode again
A universal solution.
Cleaning the cache helped

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.