6

I've created an iPad app which contains a slideshow and when this slideshow is tapped by the user he/she can entered some information.

What I'd like to do now is to display the slideshow contents on a TV when connecting the TV and iPad through AirPlay (or cable if possible, but that only seems to mirror things)

Can this be done? Can we have the slideshow run on the TV and also on iPad and then when the user taps the slideshow on the iPad the credentials input screen will show but on TV still the underlying slideshow will show and not the credentials?

How can this be done in iOS? Is it possible to display a portion of the application on the TV? So not mirroring the entire application.

Fréderic Cox
  • 321
  • 2
  • 7
  • 22
  • I'm actually experimenting with AirPlay n the iPhone 4s. I've managed to get it working with my Apple TV 2 only after setting the mirror option on the airplay control located in the task bar. I'm going to browse other possible answers here before posting a similar question. – Cliff Nov 26 '11 at 00:56
  • can you mark my answer as correct ? surely by now with this many upvotes its deemed to be correct ? – Dev2rights May 27 '13 at 22:20

2 Answers2

19

You can write the app to handle 2 UIScreens using Airplay and an Apple TV then set a seperate root view controller for both the TV UIScreen and for the iPad UIScreen. Then display the image or slideshow on the TV's view controller and run that from the events of you iPads view controller!

AMENDED AFTER CLIFS COMMENT:

So firstly in your app delegate in didFinishLaunchingWithOptions or didFinishLaunching setup a notification to receive the screen did connect.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];

Then you need to keep a reference to your separate window and push controllers to it as you would any other window.

- (void) myScreenInit:(UIScreen *)connectedScreen:(UIViewController*)mynewViewController
{    
    //Intitialise TV Screen
   if(!windowTV)
    {
        CGRect frame = connectedScreen.bounds;
        windowTV = [[UIWindow alloc] initWithFrame:frame];
        windowTV.backgroundColor = [UIColor clearColor];
       [windowTV setScreen:connectedScreen];
        windowTV.hidden = NO;
    }

    UIViewController* release = windowTV.rootViewController;
    windowTV.rootViewController = mynewViewController;
    [release removeFromParentViewController];
    [release release];
}

- (void)setTvController:(UIViewController*)mynewViewController
{     
    UIViewController* release = windowTV.rootViewController;
    windowTV.rootViewController = mynewViewController;
    [release removeFromParentViewController];
    [release release];
}

- (void)screenDidConnect:(NSNotification *)notification {
     [self myScreenInit:[notification object]];
}
Dev2rights
  • 3,469
  • 3
  • 25
  • 42
  • This answer does not include specifics on how this is done. It only mentions that it is possible with an excited exclamation point on the end. – Cliff Nov 26 '11 at 00:54
  • I removed my down vote. There is still more to the answer here. Someone completely brand new to the API (as I was a few days ago) would not see anything on a secondary screen following what you posted above. – Cliff Dec 05 '11 at 03:58
  • 7
    Well to be fair if your jumping into this without having learned about the view hierarchy documentation then you have tried to run before you can walk. – Dev2rights Dec 13 '11 at 13:56
  • This is a good answer. When I built my app AirPlay was but a pipe dream but I used a variation of this to react to a second screen (in my case via a cable to a TV/monitor) and push the correct view to it. – Alan Taylor Feb 28 '13 at 21:48
  • screenDidConnect or screenDidDisconnect notifications will not fire when you turn off your mirroring option. This is not a good answer. – Akhil PK Mar 27 '14 at 06:59
0

There appears to be a bug in iOS 5.0 which makes this tricky. You have to enable mirroring from the running task bar (scrolling all the way the left before a second screen is detected via the API. I've posted details in my question here: How to use iOS 5+ AirPlay for a second screen

Community
  • 1
  • 1
Cliff
  • 10,586
  • 7
  • 61
  • 102
  • I say the glass is half empty, they say it is half full.. A feature would clearly be some GameKit-like API calls to scan for and detect near by AirPlay compatible devices. – Cliff Oct 24 '12 at 22:48