Skip to content

Instantly share code, notes, and snippets.

@zapsleep
Created December 13, 2012 08:04
Show Gist options
  • Save zapsleep/4274903 to your computer and use it in GitHub Desktop.
Save zapsleep/4274903 to your computer and use it in GitHub Desktop.
Obtain notifies of connecting and disconnecting screens
//setting notifiers
- (void)setupScreenConnectionNotificationHandlers {
NSNotificationCenter* center = [NSNotificationCenter
defaultCenter];
[center addObserver:self selector:@selector(
handleScreenConnect:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(
handleScreenDisconnect:)
name:UIScreenDidDisconnectNotification object:nil];
}
//handling screen connection
- (void)handleScreenConnect:(NSNotification*)aNotification
{
UIScreen* newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
if (!_secondWindow)
{
_secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
_secondWindow.screen = newScreen;
// Set the initial UI for the window.
[viewController displaySelectionInSecondaryWindow:
_secondWindow];
}
}
//handling screen disconnection
- (void)handleScreenDisconnect:(NSNotification*)aNotification
{
if (_secondWindow)
{
// Hide and then delete the window.
_secondWindow.hidden = YES;
[_secondWindow release];
_secondWindow = nil;
// Update the main screen based on what is showing here.
[viewController displaySelectionOnMainScreen];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment