Adopting Scenes in iPadOS

In this Adopting Scenes tutorial, you’ll learn how to support multiple windows by creating a new iPadOS app. You’ll also learn how to update existing iOS 12 apps to support multiple windows. By Mark Struzinski.

5 (10) · 1 Review

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Add a Scene Delegate

Next, you need to add a scene delegate. The class name of this scene delegate needs to match the class name you specified for the Delegate Class Name entry in the Info.plist file the previous step.

Create a new Swift file named SceneDelegate.swift, and add the following code to the new file:

import UIKit

// 1
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  // 2  
  var window: UIWindow?
}

Here is what you entered above:

  1. Since you need to support iOS 12, wrap this class in an availability check. It will only compile for iOS 13.
  2. The operating system populates window, but it has to be present.

Since you don’t need to customize the scene configuration at runtime for this simple example, you don’t need to override anything else in this class related to window or session support.

Update the Scene Delegate

You may need to reproduce some of your existing application logic in your scene delegate. In iOS 13, the scene delegate now performs a lot of the functionality that the application delegate used to.

If you are only supporting iOS 13 and up, you’ll want to move this logic. If you are supporting iOS 13 and older operating systems, leave your app delegate code as-is and add it to the scene delegate.

The following methods map one-to-one from UIApplicationDelegate to UISceneDelegate:

UIApplicationDelegate mapping to UISceneDelegate

Now it’s finally time to run your app! If you build and run with an iOS 13 device or simulator, you should be able to create new windows using App Exposé or by dragging out of the dock.

Any new windows should show up in the multitasking view of App Exposé as well.

Multitasking view of App Exposé

Now you are ready to move into the next step: Supporting multiple scenes and maintaining state between them.

Where to Go From Here?

You can download the completed version of the project using the Download Materials button at the top or bottom of this tutorial.

You learned the main components that compose the new scene APIs and how to upgrade an existing app for multiple scene support.

You also learned how and when to create new scenes and how to update content in foreground and background scenes.

There is still a lot to learn about multiple scene support not covered in this tutorial. Some additional topics include state restoration, targeting specific scenes and updating in response to push notifications. Here are some resources for further study:

If you have any questions or comments, join the discussion in the forum below.