// MailChip Integration // Lottie Animations Integration
SkySpirit Labs

Believe in the power of innovation to shape the future with the technology.

SceneDelegate Lifecycle

Introduction to SceneDelegate Lifecycle methods. What is extracted from AppDelegate

Introduction

In previous articles we have explained the AppDelegate function and lifecycle methods. Now we will explain what responsibility SceneDelegate and what responsibilities are extracted from AppDelegate.

Before iOS13 and xcode11, creating a project would result by default to have a file AppDelegate, UIViewController, storyboard and couple more files. In contrast, now you will also see a file SceneDelegate. AppDelegate is still created and it is still the main entry point for applications. SceneDelegate extract from it the responsibility to handle what is shown on screen, manage the lifecycle events of the instance of your apps user interface. It adding the option for multi window support. The trigger for multi window support is in the Info.plist in Application Scene Manifest(look at the image on the bottom of the article).

AppDelegate

application (_:didFinishLaunchingWithOptions:)

This method still handles all what we have mentioned in the previous article.
Initialise some 3rd party frameworks, initialise CoreData or any Storage etc.
Only exception is that now creating a window and to initialise the first screen is not the right place any more. It is moved to SceneDelegate.

application (_:configurationForConnecting:options:)

Retrieves the configuration data for UIKit to use when creating a new scene. Implement this method if you do not include scene-configuration data in your apps Info.plist file, or if you want to alter the scene configuration data dynamically.
Runes ones when you start the app. If relaunch the app the windows from the previous run will be restored. If it is not implemented it will fallback to the scene from Info.plist manifest.

application (_:didDiscardSceneSessions:)

Tells the delegate that the user closed one or more of the apps scenes from the app switcher.

SceneDelegate

With the introduction of the new iPad and multi window support, applications now can have multiple scenes. The naming of methods are similar like in AppDelegate before iOS13 but responsibilities are slightly changed.

scene (_:willConnectTo:options:)

This method is called when your app creates or restores an instance of your user interface. In most case application have one scene and this will be called ones. This is now the place where to configure our first screen and window, root viewcontroller for the window and makes key window.

sceneWillEnterForeground(_:)

Called when the scene moves from background to active state.
This transition occurs for newly created and connected scenes also.
It is almost the same like applicationWillEnterForeground(_:).

sceneDidBecomeActive(_:)

This tells the user that scene became active and ready for user interaction, user events. Same as before the applicationDidBecomeActive(_:) was.
Use this method to prepare the scene, refresh the interface, start animations, start timers. Also if you use some more secured flow, you want on every event occurrence to check, should you prompt to the user Biometric Login.

sceneWillResignActive(_:)

The scene is just about to resign from active state. The app is going to background state. Same use as applicationWillResignActive(_:).
This is perfect opportunity to stop or pause ongoing task, disable timers, stop updating the interface. Also think about NSNotificationCenter Observers, i saw many times that some event triggered UI updates from this state.

sceneDidEnterBackground(_:)

The scene is already in background state. It is not presented any more.
Use this to free up memory or resources in case of complex screen. This can be like picture editing screen or if you have loaded some big files from disk.
After this moment UIKit take snapshot from scene and present app switcher. This is the moment when you want to blur sensitise data.

sceneDidDisconnect(_:)

The moment when the scene is removed from the app.
This is last moment for some resource cleanup.


Below is an example code. Colourful emojis are added to the code for easier understanding. This is shorter version as in previous articles most of use cases are already presented and they are similar to this ones.

🔵- represent AppDelegate Lifecycle methods logs
🌆- represent SceneDelegate Lifecycle methods logs
🟢- represent UIViewController Lifecycle method logs

Here are some log examples on the debug console by running the app.

Lifecycle method by AppDelegate, SceneDelegate and UIViewController
Lifecycle method. Red — app goes to background. Green- app comes back from the background.
Killing the application.

If you created a project with xcode11 or later you can still opt out from SceneDelegate. You need to delete from Info.plist the Application Scene Manifest.

Application Scene Manifest deletion

Outro

With this article the Lifecycle series are finished.🙂
Hope that it was helpful and most important to practice on own use cases.

If you got to this point, thanks for reading. 🙂 If you like the content please 👏, share, subscribe, buy a coffee it means to me. If you have some suggestions or questions please feel free to comment.

Next Post

Previous Post

Leave a Reply

© 2025 SkySpirit Labs

Theme by Anders Norén