Skip to main content

SceneDelegate Migration Issues

Overview

There is no self-respecting iOS Developer who doesn't know the wonderful AppDelegate. This is the place where the control of various shared behaviours in the application is managed. It was born on iOS 2 and was responsible for the following tasks. The app delegate is effectively the root object of your app, and it works in conjunction with UIApplication to manage some interactions with the system. Like the UIApplication object, UIKit creates your app delegate object early in your app’s launch cycle so it’s always present. Used to handle the following tasks:

  • Initializing your app’s central data structures.
  • Configuring your app’s scenes.
  • Responding to notifications originating from outside the app, such as low-memory warnings, download completion notifications, and more.
  • Responding to events that target the app itself, and aren’t specific to your app’s scenes, views, or view controllers.
  • Registering for any required services at launch time, such as Apple Push Notification service.



Responding to life-cycle events in a scene-based app

This was the case for a long time, but with the arrival of iOS 13 Apple decided to take responsibility away from the AppDelegate by separating the entire lifecycle management part of the scenes to a new ally, the SceneDelegate.


life-cycle events of an iOS app

You can read in depth here. I probably haven't told you anything up to this point that you didn't already know, but one thing that a lot of developers waste a lot of time sticking with is that if we make this change, if somewhere in our code we access the UIWindow creation as follows: 

UIWindow(frame: UIScreen.main.bounds)

After that, then use it to present a new view in the following way:

swift code to present a viewcontroller

Create UIWindow after SceneDelegate Migration

Now if our code has any UIWindow instances created with frame we will have to replace them with the following instruction. 


UIWindow(windowScene: windowScene)
To build such a windowScene we can use the following implementation before. 

swift code to create a windowScene

Conclusion

It is very common to find many manuals and guides to migrate to SceneDelegate by making changes to the Info.plist and AppDelegate. But this nuance is neglected and it seems to me that it can waste valuable time to find out why some modal screens are not being presented after migration. 

Best regards and see you in other posts!

Comments

© 2020 Mobile Dev Hub