Display one thing on iPad and another on Apple Tv?
Asked Answered
T

1

8

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

Trotskyite answered 11/7, 2013 at 21:12 Comment(7)
Maybe Apple's "ExternalDisplay" sample code would be helpful: developer.apple.com/library/ios/#samplecode/ExternalDisplay/…Transfiguration
Sorry I wasn't clear enough, I was wondering if it is possible to do this via Airplay. Without a cable.Trotskyite
possible duplicate of Airplay from iPad - a separate UIView to display on Apple TVAmaranthine
It is possible, I already did some experiments last year with that concept - btw called second screen - and did some audio visualization on apple tv while listening to radio on the iphone. it works :)Chura
See blog.redfin.com/devblog/2012/05/…Amaranthine
Using the details at the blog post I linked, I was able to easily display one view controller on my iPad and a 2nd view controller on the Apple TV (using a second UIWindow tied to the second UIScreen). Very cool. This gives me lots of ideas for my app.Amaranthine
Maddy, are you willing to share your "Proof of Concept" app?Trotskyite
A
15

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.

Amaranthine answered 12/7, 2013 at 2:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.