-1

The question says it all.

There's the following line in apple documentation,

Scenes are opt in, but you must support them if you want to display multiple copies of your app’s UI simultaneously.

It's not mentioned whether the SceneDelegate is mandatory or optional or a recommendation (I'm aware that the SceneDelgate is used to handle the lifecycle of the scene). In a iOS 13+ device, can I create an app without SceneDelegate?

I defined the UIWindow variable in the AppDelgate and set the ViewController in application(didFinishLaunchingWithOptions), like before iOS 13. But that doesn't work and displays a blank screen.

And thus, this question. Is Scenedelgate mandatory even if we don't opt for multiple scenes? Here's my observation:

Multiple scenes are optional. But you still have to support at least one scene... and for that, SceneDelegate is mandatory.

If I'm wrong and SceneDelegate is optional (like described in this stackoverflow post), please help with the flows.

NightFuryLxD
  • 847
  • 5
  • 15
  • 1
    See https://stackoverflow.com/q/59006550/1187415 – Martin R Nov 29 '22 at 14:17
  • I added and removed the Scene configuration from plist file many times to study the behaviour, but I missed to set 'Enable Multiple Windows' to No. It was 'Yes' the whole time and that led to an empty black screen :(. That was the problem. Solved now. Thank you. – NightFuryLxD Nov 30 '22 at 13:30

1 Answers1

2

In a iOS 13+ device, can I create an app without SceneDelegate?

Yes. All apps do have scenes, but if you go with the app-delegate-only architecture, a single UIWindowScene will be created behind the scenes (pun intended). The app will run perfectly well on both iPhone and iPad, with all the usual lifetime events arriving as usual into the app delegate (though I do not know what will happen on Apple Silicon).

I defined the UIWindow variable in the AppDelgate and set the ViewController in application(didFinishLaunchingWithOptions), like before iOS 13. But that doesn't work and displays a blank screen.

This is because you did not correctly convert from the scene delegate architecture, which is provided by the app template you started with, to an app delegate architecture. Basically, you've left pieces of the scene delegate architecture lying around. Perhaps you did not delete all references to the scene delegate; perhaps you forgot to delete the UIApplicationSceneManifest entry from the Info.plist. Whatever the reason, the result is that the runtime thinks this app still uses scene delegate architecture, and it then fails to find certain pieces that it's looking for and shows the blank screen.

So, just to sum up what to do when you've started with the built-in app template:

  1. Delete the SceneDelegate.swift file.

  2. In the App Delegate, delete the two UISceneSession methods.

  3. In the App Delegate, add a window reference as an instance property: var window: UIWindow?

  4. In the Info.plist, completely delete the entire UIApplicationSceneManifest entry (and save).

  5. Profit.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Are there any benefits to this approach - just using the scene delegate to set up a single scene app seems less effort (effectively drop-in boilerplate, rather than all the above and still almost the same boilerplate in a different file)? – flanker Nov 29 '22 at 15:36
  • @flanker Not that I know of. Usually one gets into this situation because of supporting iOS 12 or earlier, either now or in the past. In other words, you typically come at it from the other direction: rather than starting with the current template and going backward, you start with an older template and go forward. So, I use the new architecture for new projects, but old projects are not harmed by retaining the old architecture. Still, that is not what the OP asked; the OP asked how to go backward and that's what I answered. I didn't say it was a good idea. :) – matt Nov 29 '22 at 15:53
  • Thanks @matt. I do similar, but was wondering if I was missing a trick :) – flanker Nov 29 '22 at 16:06
  • I added and removed the Scene configuration from plist file many times to study the behaviour, but I missed to set 'Enable Multiple Windows' to No. It was 'Yes' the whole time and that led to an empty black screen :(. Thanks. – NightFuryLxD Nov 30 '22 at 13:29
  • 1
    That is actually the same as what I said. :) You are changing the value of a key within the UIApplicationSceneManifest entry. But what I'm suggesting is that you may as well remove that entry altogether. – matt Nov 30 '22 at 13:32