Fill connected displays with additional content from your app.
The user can connect additional screens to an iOS device at any time using AirPlay or a physical cable. Each additional screen represents new space on which to display your app’s content, and is managed by a
UIScreen object. For example, a game might show its content on a connected display and show game controls on the iPhone screen, as illustrated in Figure 1.
To take advantage of the additional space offered by a connected screen, create a
UIWindow object and set its
screen property to the corresponding screen object. When a new screen is connected, UIKit delivers a
did notification to your app. When a screen is disconnected, UIKit delivers a
did notification. Use connection and disconnection notifications to show or hide additional windows. If your app is suspended when a notification arrives, UIKit delivers it when your app begins running again.
Listing 1 uses the screen connection notification to configure a new window for the app. The code sizes the window to fill the screen dimensions and assigns the appropriate screen object to it. The
configure method is a custom method that assigns a view controller to the window's
root property. After showing the window. the code saves a reference to it.
Listing 2 removes the window associated with a screen that has been disconnected from the device.
It is possible for an external screen’s resolution or aspect ratio to change while your app is connected to it. To update your content in response to those changes, observe the