Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

ios - Display one thing on iPad and another on 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...