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

iPadOS recently debuted alongside iOS 13.1 and adopts an exciting new feature available for the first time: window support!

Window support allows users to create multiple windows of your running app. Windows can contain similar content, or a new window can contain a completely different view, such as accessory information.

In this tutorial, you’ll learn how to:

  • Update your existing apps to include scene support.
  • Interact with the new set of objects in the app delegate to support multiple windows.
  • Create new windows and update them whether they’re in the foreground or background.

Before getting started, make sure to click the Download Materials button at the top or bottom of this tutorial.

Getting Started

There are some fundamental changes to the application lifecycle with iPadOS and iOS 13. Windows are now managed by a UISceneSession.

There is a new set of objects to manage the window lifecycle: UISceneSession, UISceneDelegate, and UISceneConfiguration. Scenes manage windows, and they have their own dedicated lifecycle managed outside of the UIApplication instance.

These changes to the components also change the way you interact with UIApplicationDelegate. A lot of the delegate callbacks used in iOS 12 have now moved to UISceneSessionDelegate.

Scene Components

There are several new objects that you’ll have to interact with to support multiple scenes.

UIWindowScene is a subclass of UIScene and the most common type of scene you’ll interact with.

This object represents one instance of your app’s user interface. You shouldn’t instantiate UIWindowScene directly; UIKit will create it for you. In most cases, you’ll interact with UIScene through its delegate, UISceneSessionDelegate.

UIWindowSceneDelegate is a delegate protocol that extends from UISceneDelegate and contains the core methods you’ll use to respond to UIWindowScene lifecycle events.

You don’t instantiate this object directly. UIKit creates it for you and pairs it with each UIWindowScene. Your Info.plist dictates how UIKit creates the scene delegate. You’ll learn how to set this up in a later section.

This object contains information that tells UIKit how to instantiate your scene. You configure a UISceneConfiguration in code or in your Info.plist.

Apple’s preferred method is to use the Info.plist, and this tutorial will also use the plist file for scene configuration.

This object contains information about an app’s scene. It manages the lifecycle of exactly one UIScene and contains persisted interface states. The operating system creates scene sessions. You shouldn’t instantiate them directly. The graph below shows the relationship between some of these objects.

Graph depicting different scene session objects

iPadOS and Multiple Scenes

iPadOS adds several new user interactions related to scene support. Time to explore how users employ these new interactions.

Creating New Windows

A user creates new windows using several different methods:

If your app declares multiple-window support, your user can enter multitasking view by swiping up to show the dock and on your app icon in the dock while the app is already running. This shows the following view of your app’s windows, including a plus button to create a new window:

App Exposé Multitasking View

You should only create new windows in reaction to explicit user interaction, such as the user tapping a New Window button. This allows your user to control windows and window management. You create a new window programmatically using a new API on UIApplication.

A drag and drop session can instantiate a new scene. The use case for this interaction is dragging an object from your app to expose a new view with detail.

For example, a user drags a list item out of the list, and it instantiates a new window side-by-side with the existing list view. The new window content contains the detail view of the item.

The Example App

If you haven’t already, download the example app and open it in the begin folder. Build and run it on an iPad simulator to check it out — it’s a simple app that allows you to create notes, view them in a list and delete them. You can also view and update your profile.

The starter version of the app does not support multiple windows. You can only launch one instance of the app at a time.

Add note view

This is a SwiftUI app using Core Data to persist notes and user defaults to store profile information. This allows you to work on multiple-window support without worrying about backing storage, network requests or sync issues.

Add a few notes by tapping the plus button in the navigation bar in the top-right. You’ll see the new note modal launches in a sheet over top of the existing content:

New note modal

Add or update some profile information by tapping the profile button in the navigation bar on the top-left. The profile modal displays in a sheet:

Update profile view

The Plan

The rest of this tutorial will teach you how to implement multiple windows in an iOS 13 app.

You will:

  • Display multiple windows.
  • Add new scene types.
  • Sync data across windows, whether they are in the foreground or background.

Adding Multiple Scene Support

First, you’ll add support for multiple scenes to your app. If you created your app with Xcode 11, then Xcode set up the scene delegate and scene configuration for you. Xcode also handles the connection between app delegate and scene delegate in the default iOS 13 template.

If you are upgrading an existing app from iOS 12, follow the steps in the Updating Your App from iOS 12 section before you get started.

Update the Info.plist

First, update Info.plist to support multiple scenes:

  1. Open Info.plist.
  2. Expand the Application Scene Manifest node.
  3. Set the value of Enable Multiple Windows to YES.

After you have set this value, you can launch multiple windows of the same scene.

Build and run now on an iPad simulator.

Switch to landscape to give yourself more room. You can now perform the following actions with the app:

Add Window

Slideover

Split Window

  • While the app is in the foreground, slide up from the bottom bezel to launch the dock. Tap and hold the right-hand app icon. Select Show All Windows from the menu. You’ll now see the App Exposé view and can tap the plus icon on the top right to launch a new window:
  • With the app in the foreground, slide up to show the dock again. This time, drag the app icon out of the dock until it becomes a hovering window. Drop the window on the right or left side of the screen. You now have a second window running in slideover mode:
  • With the slideover window still running, tap and hold on the drag handle at the top of the window. Pull down and to the right until the window changes shape. Drop the window onto the side of the screen. Now you have two windows running side-by-side. You can also move the split handle in the middle to resize these windows:

That’s a lot of support for updating one value in the plist! Moving forward, adding support for additional scenes is not so simple. You have to consider where it makes sense to add support and how to keep your scenes in sync.