Redeem Now
Read More
Read now

Difference between Scene Delegate and App Delegate

If you have created a project on Xcode 11 and above you have noticed h new file created as SceneDelegate.swift. Let’s check below the difference between Scene Delegate and App Delegate.

If we create a new project before xcode 11, it will create some default files, as shown in below image.

 

From Xcode 11 onwards you might have noticed that along with the default files, it will create a new file as SceneDelegate.swift. As shown in the below image.

In apps prior to iOS 13, AppDelegate is the main entry point of the app, and in it, the application launches,  and it handles app background and foreground states.

But from iOS 13 the responsibilities of app delegates have been split between AppDelegate and SceneDelegate.

That’s how the new multi-window support feature is introduced in iPad OS.

Functions of AppDelegate and SceneDelegate

AppDelegate:

Even after iOS 13, the AppDelegate is still the main entry point of an application.

By default AppDelegate.swift have three main methods.

1.func application(_:didFinishLaunchingWithOptions:) -> Bool

In iOS 12 or earlier, you might have used this method to create and configure a UIWindow object and assigned a UIViewController instance to the window to make it appear.

If your app is using scenes, your AppDelegate is no longer responsible for doing this.

Since your application can now have multiple windows or UISceneSessions active, it doesn’t make much sense to manage a single-window object in the AppDelegate

2.func application(_:configurationForConnecting:options:) -> UISceneConfiguration

Whenever the application needs a new scene or window.

3.func application(_:didDiscardSceneSessions:)

Whenever the user discards a scene by swiping it from the multitasking window or if discarded programmatically.

This method is called for every discarded scene shortly after the (_:didFinishLaunchingwithOptions:) method is called if the app isn’t running when the user discards the scene.

In addition to these methods, AppDelegate can still handle URLs, cache memory, app termination, push notifications, location services, and many more.

SceneDelegate:

From iOS 13, SceneDelegate takes up some responsibilities from AppDelegate, particularly UIWindow in AppDelegate is now UIScene in SceneDelegate.

What is displaying on the screen is the responsibility of SceneDelegate. There are 6 default functions in SceneDelegate.

1.scene(_:willConnectTo:options:)

It will create a new window, sets the root view controller, and makes this window the key widow that will be displayed.

2.sceneWillEnterForeground(_:)

When the app becomes active for the first time or when transitions from background to foreground.

3.sceneDidBecomeActive(_:)

When the scene has moved from an inactive state to an active state.

4.sceneWillResignActive(_:)

When the scene will move from an active state to an inactive state.

This may occur due to temporary interruptions (ex. an incoming phone call).

5.sceneDidEnterBackground(_:)

When the scene transitions from the foreground to the background.

6.sceneDidDisconnect(_:)

While releasing the scene by the system.

The scene may re-connect later, as its session was not necessarily discarded (see application:didDiscardSceneSessions instead).

 

Hope the difference between Scene Delegate and App Delegate is clear now, if you still have any doubt or query you can let me know over the comment section.

Thanks for reading 🙂

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close