IOS AirPlay Second Screen Tutorial

I am considering adding AirPlay features to one of my ViewControllers. The view controller simply displays the UIWebView. I want to add a button that displays this content on an Apple TV. I know that system-wide mirroring can be done, but it does not fill the entire screen, there are black bars around it. I searched on the Internet, but most of all that I found is a way back with iOS 5 and outdated. Could someone point me towards a textbook or drop library to help? I just need the mirroring of only one view to be full-screen on Apple TV.

So far, this is what I have done, but I believe that it only creates a second window, without putting anything into it.

In AppDelegate, I create a property for it:

@property (nonatomic, retain) UIWindow *secondWindow; 

In didFinish, the AppDelegate method runs:

  NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(handleScreenDidConnectNotification:) name:UIScreenDidConnectNotification object:nil]; [center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:) name:UIScreenDidDisconnectNotification object:nil]; 

Then in AppDelegate I have:

 - (void)handleScreenDidConnectNotification:(NSNotification*)aNotification { UIScreen *newScreen = [aNotification object]; CGRect screenBounds = newScreen.bounds; if (!self.secondWindow) { self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds]; self.secondWindow.screen = newScreen; // Set the initial UI for the window. } } - (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification { if (self.secondWindow) { // Hide and then delete the window. self.secondWindow.hidden = YES; self.secondWindow = nil; } } 

In the viewController, in which I would like to enable the display of WebView on Apple TV, I have:

 - (void)checkForExistingScreenAndInitializeIfPresent { if ([[UIScreen screens] count] > 1) { // Get the screen object that represents the external display. UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1]; // Get the screen bounds so that you can create a window of the correct size. CGRect screenBounds = secondScreen.bounds; appDelegate.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds]; appDelegate.secondWindow.screen = secondScreen; // Set up initial content to display... // Show the window. appDelegate.secondWindow.hidden = NO; NSLog(@"YES"); } } 

I got it all from here . However, all that it shows, so I'm not sure how to get content on this screen.

+6
source share
3 answers

Depending on what is happening in your web view, you will either have to make a second pointer on the same page, or move an existing one to a new window. In any case, you relate to the second window in much the same way as to the main window of your application - add views to it, and they should appear on the second display.

+3
source

Currently, there are only two options for creating Airplay mirroring: system-wide monitoring and fully custom mirroring. Since system-wide mirroring is not a solution for you, you will have to go along the path that you have already identified in your code snippets.

As Noah noted, this means providing content for the second screen as well as providing it for the internal display. As far as I understand, you want to show the same data / website as before on the internal display, but display it differently in the remote view / web view (for example, in different proportions). One way could be a single webview that follows the other in the master / slave setup. You will need to track changes (for example, scolling the user) in the master device and distribute them to the slave. The second way is to drop the original content of the webview into the buffer and partially draw this buffer into a "mute" UIView. This will be a little faster since the website will not need to be loaded and displayed twice.

0
source

All Articles