When we run an application on iOS, the first function called is (_: didFinishLaunchingWithOptions: ) in the AppDelegate. In the AppDelegate we can also find a series of functions that are executed when the state of the application changes (going to the background, returning to the foreground, etc.). With Xcode 11, a new SceneDelegate class appears when generating a new project. But, what is the function of SceneDelegate in iOS 13. Now, in the SceneDelegate class in iOS 13 the concept of window (window) has been changed to scene, since now an application can have more than one scene . That is, we can open two or more windows of the same application and interact with each other.

Functions of the SceneDelegate class

The main function in the SceneDelegate class is:

By default, this function creates the initial view, a new window (UIWindow), sets its controller (rootViewController) and makes it the main window (key window). In this case, the UISceneSession instance that we use in UIWindow (windowScene:) controls the window that the user sees.

This function, scene (_: willConnectTo: options:), also allows you to restore a scene if it has previously been deactivated (as, for example, when going to the background).

In the SceneDelegate class we find some of the functions that were in the AppDelegate class, but referred to the scenes:

Once a scene is created or reconnected, the first method that is called is sceneWillEnterForeground(_ scene:) when the scene will appear (either because it is activated for the first time or because it goes from second to foreground).

Next, the sceneDidBecomeActive(_ scene: ) method is called, when the scene is ready to receive and respond to user events.When the application is about to stop responding to user events, the sceneWillResignActive(_ scene:) method is called, and when it goes from the foreground to the background, the sceneDidEnterBackground(_ scene:) method.

New methods on the AppDelegate class

On the other hand, in the AppDelegate class there are two new methods related to the scenes, since now the new life cycle of the scenes sessions is managed by UIApplicationDelegate:

Modification in the Info.plist file

Together with these new delegates, Xcode creates a new entry (Application Scene Manifest) in the Info.plist file:

This new entry we find these fields:

  • Enable Multiple Windows. If its value is TRUE, users can open multiple windows of an application (on iPadOS).
  • Scene Configuration. It contains the Application Session Role field, an array (so we could have multiple configurations), whose first item contains a name and a delegate for the scene.
Categories: Swift

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow on Feedly
shares