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.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Adopting Scenes in iPadOS
30 mins
- Getting Started
- Scene Components
- UIWindowScene
- UIWindowSceneDelegate
- UISceneConfiguration
- UISceneSession
- iPadOS and Multiple Scenes
- Creating New Windows
- Through the App Exposé Multitasking View
- Via an Explicit User Interaction
- Via Drag and Drop
- The Example App
- The Plan
- Adding Multiple Scene Support
- Update the Info.plist
- Adding a New Scene
- Create a New Scene Delegate
- Add a New Scene to the Scene Manifest
- Add UI to Display the New Scene
- Create a Constant Declaration for Scene Names
- Create an enum Declaration for User Activities
- Add UI to Create a New Window
- Update the App Delegate to Configure the New Scene
- Keeping Scenes up to Date
- Keeping Foreground Scenes up to Date
- Keeping Background Scenes up to Date
- Attaching Identifying Information to Scenes
- Updating Scenes from the Background
- Updating Your App From iOS 12
- Update Info.plist
- Add a Scene Delegate
- Update the Scene Delegate
- Where to Go From Here?
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:
- Since you need to support iOS 12, wrap this class in an availability check. It will only compile for iOS 13.
- 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
:
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.
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:
- There are several WWDC videos on this topic. Two good ones from WWDC19 are: Introducing Multiple Windows on iPad and Architecting Your App for Multiple Windows.
- Make sure you review Apple’s documentation for UIScene, UIWindowScene, UISceneDelegate, and UIWindowSceneDelegate.
- You may also want to checkout Apple’s sample project: Supporting Multiple Windows on iPad.
If you have any questions or comments, join the discussion in the forum below.