Programmatically switch between "mirror" and "additional content" with windowExternalDisplayNonInteractive

I'd like to share an app's screen in two modes. First in a standard mirroring mode and second in an "additional content" mode (very likely with a session role windowExternalDisplayNonInteractive).

I found that the Keynote app on iOS does a very nice example of what I want to achieve when sharing an iPhone using AirPlay to an AppleTV.

  • sharing a screen results in mirroring the screen on the TV
  • tapping the play button in Keynote switches to "additional content" where iPhone and TV show different content
  • leaving the additional content mode returns to "mirroring" where TV and iPhone show the same content

Is there an example for implementing such a feature?

I am able to successfully use the external display (windowExternalDisplayNonInteractive) and show additional content there.

How can I programmatically "detach" the additional content from the external display and activate mirroring mode?

Searching the Developer Forums for windowExternalDisplayNonInteractive reveals some discussions, which include valuable information, however, returning to mirror mode does not seem to be covered.

How can I programmatically "detach" the additional content from the external display and activate mirroring mode?

Unfortunately this is a bit buried in documentation at the moment and then not really even that clear. I'll file a feedback to make this better.

The solution is implied here: https://developer.apple.com/documentation/uikit/uiscreen/1617829-mirrored

To kick the system out of mirroring mode for windowExternalDisplayNonInteractive, simply create a UIWindow there. To make it go back to mirroring, simply remove your UIWindow from the scene through use of the windowScene property (just set it to nil): https://developer.apple.com/documentation/uikit/uiwindow/3197962-windowscene

Programmatically switch between "mirror" and "additional content" with windowExternalDisplayNonInteractive
 
 
Q