Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display one thing on iPad and another on Apple Tv?

Tags:

ios

ipad

apple-tv

I have an app idea, but I'm not sure if it's possible.

I was wondering if I'm able to display one thing on the iPad ( or iPhone ) screen, and something totally different on the Apple Tv at the same time. For example, a quiz app, where the question is displayed on the Apple Tv, and the multiple choices are listed on the iPad for the user to pick.

I'm not sure if this is possible or if you can only Mirror the iPad screen onto the Apple Tv.

If there is some "Proof of Concept" example code, I'd love to take a look. Thank you so much. Chris

like image 238
Chris Young Avatar asked Jul 11 '13 21:07

Chris Young


1 Answers

Turns out that is is pretty simple to support two screens: the primary screen of the iOS device and a secondary screen (either an external display or mirroring on an Apple TV).

Based on information from the blog post Creating a Dual-Screen AirPlay Experience for iOS and Apple TV, you don't need to do much.

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

Once you have a second screen, you need to create a new window for it. Code like the following can be used:

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 setup, create a view controller, make it the window's root view controller, and show the window:

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

This is pretty much it other than proper handling of the notifications. Keep in mind that you can't get any touch events on the 2nd display so make sure whatever you show is basically display-only.

Depending on your app, you might have the 2nd screen/window being used throughout the lifetime of the app (as long as the 2nd screen is available any way). Or you might only create and use the 2nd window/screen under certain circumstances. When you don't setup the 2nd window/screen, your app will simply be mirrored to the 2nd display or Apple TV.

The last piece is to turn on mirroring to the Apple TV. This is done on the iOS device, not in the app.

The blog post I linked has a few more details worth reviewing.

like image 134
rmaddy Avatar answered Oct 07 '22 01:10

rmaddy