Last active
October 12, 2015 10:08
-
-
Save martinpilch/4011154 to your computer and use it in GitHub Desktop.
AirPlay video mirroring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
//... Initialization of application | |
//Screen notification handlers | |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; | |
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:) | |
name:UIScreenDidConnectNotification object:nil]; | |
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:) | |
name:UIScreenDidDisconnectNotification object:nil]; | |
//Init second screen if presented | |
[self initSecondScreen]; | |
return YES; | |
} | |
#pragma mark - | |
#pragma mark Display handling | |
- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification { | |
//Handle AirPlay device connection | |
[self initSecondScreen]; | |
} | |
- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification { | |
//Handle AirPlay device disconnection | |
if (self.secondaryWindow) | |
{ | |
// Hide and then delete the window. | |
self.secondaryWindow.hidden = YES; | |
self.secondaryWindow = nil; | |
} | |
} | |
- (void)initSecondScreen | |
{ | |
if ([[UIScreen screens] count] > 1) | |
{ | |
UIScreen *screen = [[UIScreen screens] lastObject]; | |
//Init second window do display content | |
if (!self.secondaryWindow) | |
{ | |
self.secondaryWindow = [[UIWindow alloc] initWithFrame:screen.bounds]; | |
self.secondaryWindow.screen = screen; | |
self.secondaryWindow.hidden = NO; | |
} | |
//Controller to display content on AirPlay device | |
self.secondaryWindow.rootViewController = [[AirPlayerViewController alloc] init]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment