Show one thing on an iPad and another on an Apple TV?

I have an application idea, but I'm not sure if this is possible.

I was wondering if I could show one thing on an iPad (or iPhone) screen and something completely different on an Apple TV at the same time. For example, a quiz application where the question is displayed on an Apple TV, and several options are listed on the iPad for the user.

I'm not sure if this is possible, or if you can only flip the iPad screen on your Apple TV.

If there is an example code "Proof of Concept", I would like to take a look. Thank you so much. Chris

+8
ios ipad apple-tv
source share
1 answer

It turns out that it’s quite simple to support two screens: the main screen of the iOS device and the secondary screen (either an external display or mirroring on an Apple TV).

Based on information from the blog post Creating the AirPlay two-element experience for iOS and Apple TV , you don’t have to do much.

Basically you need to check the screens property from UIScreen . There are also notifications you should listen to ( UIScreenDidConnectNotification and UIScreenDidDisconnectNotification ) so you know if the number of screens changes while your application is running.

As soon as you have a second screen, you need to create a new window for it. You can use the following code:

 if ([UIScreen screens].count > 1) { if (!_secondWin) { UIScreen *screen = [UIScreen screens][1]; _secondWin = [[UIWindow alloc] initWithFrame:screen.bounds]; _secondWin.screen = screen; } } 

where _secondWin is a UIWindow ivar.

Once the window is configured, create a view controller, make it the root window controller, and show the window:

 SomeViewController *vc = [[SomeViewController alloc] init...]; _secondWin.rootViewController = vc; _secondWin.hidden = NO; 

This is very different from the proper handling of notifications. Keep in mind that you cannot get any touch events on the 2nd display, so make sure that everything you show is basically just for display.

Depending on your application, you may have a 2nd screen / window that is used throughout the life of the application (as long as a second screen is available). Or you can only create and use a second window / screen in certain circumstances. When you do not configure a second window / screen, your application will simply be mirrored on the second display or Apple TV.

The last part is to enable mirroring on your Apple TV. This is done on the iOS device, not in the application.

The blog post I linked has some details worth considering.

+14
source share

All Articles