I am trying to enable AirPlay support in my application. I do not make a video; I want to use an external display as a "second display".
Here is my problem: if I select "AppleTV" from my AirPlay button, my application will not receive a notification. The only time my application is notified about this, when I leave the application, go to the AirPlay button at the OS level, select "AppleTV" and turn on mirroring. If I turn off the mirror, my application will report that the external display is not working.
So:
- Why is my application not notified when I select an external display from within my application?
- Why does my application receive a notification about the presence of an external display when I turn the mirror on ... and not earlier? I obviously misunderstand something, but it seems that turning on mirroring should inform my application that the external screen has disappeared (and is not now available, since the OS should now use this external display for mirroring.)
Sample code below. Thanks in advance for your help!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. // Is there already an external screen? if (UIScreen.screens.count > 1)] { [self prepareExternalScreen:UIScreen.screens.lastObject]; } // Tell us when an external screen is added or removed. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidConnect:) name:UIScreenDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil]; self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; // Add AirPlay control to view controller. MPVolumeView* airplayButtonView = [[MPVolumeView alloc] init]; airplayButtonView.frame = CGRectMake(300, 300, 50, 50); airplayButtonView.backgroundColor = [UIColor blackColor]; airplayButtonView.showsVolumeSlider = NO; airplayButtonView.showsRouteButton = YES; [self.viewController.view addSubview:airplayButtonView]; [self.window makeKeyAndVisible]; return YES; }
source share