Understanding Scene Delegate & App Delegate

In Xcode 11 & iOS 13 +

The AppDelegate will be responsible for the application lifecycle and setup. The SceneDelegate will be responsible for what is shown on the screen (Windows or Scenes) handle and manage the way your app is shown.
AppDelegate prior to iOS 13

AppDelegate and Scene Delegate responsibilities

The AppDelegate!!!

Even in iOS 13, the AppDelegate is still the main point of entry for an application. AppDelegate methods are called for application level lifecycle events. In the default AppDelegate.swift there are three methods that Apple considers to be important that we have to consider and let’s look into them:

1. func application(_:didFinishLaunchingWithOptions:) -> Bool
2. func application(_:configurationForConnecting:options:) -> UISceneConfiguration
3. func application(_:didDiscardSceneSessions:)
  • func application(_:didFinishLaunchingWithOptions:) -> Bool
  • func application(_:configurationForConnecting:options:) -> UISceneConfiguration
  • func application(_:didDiscardSceneSessions:)
AppDelegate from iOS 13

The SceneDelegate!!!

From iOS 13 and later, SceneDelegate takes up some responsibilites from AppDelegate. In particular related to UIWindow from AppDelegate is now UIScene in SceneDelegate. An app can have more than one scene which mostly handles application interface and app content. So, the SceneDelegate is responsible for what’s displayed on the screen in terma of UI and data.

The new SceneDeleagate from iOS 13
1. scene(_:willConnectTo:options:)
2. sceneDidDisconnect(_:)
3. sceneDidBecomeActive(_:)
4. sceneWillResignActive(_:)
5. sceneWillEnterForeground(_:)
6. sceneDidEnterBackground(_:)
  • scene(_:willConnectTo:options:)
  • sceneWillEnterForeground(_:)
  • sceneDidBecomeActive(_:)
  • sceneWillResignActive(_:) and sceneDidEnterBackground(_:)
  • sceneDidDisconnect(_:)

Conclusion

The main reason for Apple to add UISceneDelegate to iOS 13 was to create a good entry point for multi-windowed applications. By the above theory you might have understood the roles of AppDelegate and SceneDelegate in iOS 13 and their life cycle events. AppDelegate is responsible for handling application-level events, like app launch and the SceneDelegate is responsible for scene lifecycle events like scene creation, destruction and state restoration of a UISceneSession.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store