Tell the system about your app’s scenes, including the objects you use to manage each scene and its initial user interface.
In iOS 13 and later, users can create multiple copies of your app’s UI and toggle between them in the app switcher. On iPad, users can also display one copy of your app’s UI side by side with another copy. For each copy of your app’s UI, you use a scene object to manage the window, views, and view controllers that present the UI onscreen.
When the user requests a new scene, UIKit creates the corresponding scene object and handles its initial setup. To do that, UIKit relies on information that you provide. Apps must declare the types of scenes they support and the objects they use to manage those scenes. You can do that statically in your app’s
Info file or dynamically at runtime.
Enable Scene Support in Your Project Settings
Apps must explicitly opt in to scenes, which you do by updating your app’s configuration settings:
Open your Xcode project.
Navigate to the General settings for your app target.
Enable the "Supports multiple windows" checkbox in the Deployment Info section.
When you enable the multiple windows option, Xcode adds the UIApplicationSceneManifest key to your app’s
Info file. The presence of this key tells the system that your app supports scenes. The value of this key is a dictionary, which initially contains only the
The value of the
UIApplication key tells the system whether your app actually supports multiple simultaneous scenes. Xcode initially sets the value of this key to
true, but you can disable the feature if you want to display only one scene at a time. Supporting multiple scenes requires extra work on your part to ensure that your scenes do not interfere with each other. For example, if your scenes use the same shared data structures, they must coordinate access to those structures to preserve the integrity of your app’s data.
Configure the Details for Each Scene
UIKit handles the creation of your app’s scenes using information that you provide. The simplest way to provide this information is in your app’s
Open your Xcode project and select the
Click the plus (+) button of the Application Scene Manifest entry. This entry corresponds to the UIApplicationSceneManifest key. If it is not present, add it as described in Enable Scene Support in Your Project Settings.
From the menu that appears, select Scene Configuration.
In the Scene Configuration entry, click the plus (+) button.
Select Application Session Role to add a main scene to your app.
Fill in the scene details in the provided entry.
Most apps need only one main scene, but you may add multiple scenes and configure each differently. For example, you might include a second scene specifically to display notification-related content. UIKit requires the following information for each scene:
The class name of the scene, which is
The class name of the custom delegate object your app uses to manage the scene. The class must adopt the
A unique name that your app uses to identify the scene internally.
The name of the storyboard containing the scene’s initial UI. Specify the name without the
For more information about how to configure your scenes, see UISceneConfigurations.
Create the Interface for Your Scene
You specify the UI for your scene using storyboards. The storyboard you assign to the
UIScene key contains the initial view controller you want to display for your scene. In addition to creating the scene object, UIKit creates a window for your scene automatically and installs the initial view controller from your storyboard in it. You can replace that view controller programmatically using the methods of your
Change Your Scene’s Configuration Dynamically
Before actually creating your scene object, UIKit calls the
application(_: method of your app delegate to let you change the scene-related details. You might use this method to adjust the scene configuration based on the options that UIKit provides. For example, when the system passes a notification response to your scene, you might specify a different storyboard with your notification-related interface.
If you don’t implement configure scenes dynamically, UIKit uses the information in your app’s
Info file to create your scenes.
Adopt Scene-Based Life-Cycle Semantics
Adding support for scenes changes how your app responds to life-cycle events. In an app without scenes, the app delegate object handles transitions to the foreground or background. When you add scene support to your app, UIKit shifts that responsibility to your scene delegate objects. Scene life cycles are independent of one another, and independent of the app itself, so your scene delegate objects must handle the transitions.
If your app also supports iOS 12, you can handle life-cycle transitions in both your app delegate and scene delegate objects. UIKit notifies only one delegate object. In iOS 13 and later, UIKit notifies your scene delegate objects. In iOS 12 and earlier, UIKit notifies your app delegate.
For information about how to handle life-cycle events, see Managing Your App's Life Cycle.