iosipadios-simulatorexternal-display

iPad simulator and external screen


i have an application that i wish to show on external screen.

The problem is that when i go Hardware -> External displays and select one of them - the events aren't triggered. Why?

This also doesn't get entered:

if ([[UIScreen screens] count] > 1)

So i have added next code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     //SOME CODE ...
     [self checkForExistingScreenAndInitializeIfPresent];
     [self setUpScreenConnectionNotificationHandlers];
     return YES:
}

- (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's bounds so that you can create a window of the correct size.
    CGRect screenBounds = secondScreen.bounds;

    self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
    self.secondWindow.screen = secondScreen;

    self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
    self.externalWindow.view.frame=screenBounds;

    self.secondWindow.rootViewController=self.externalWindow;
    // Set up initial content to display...
    // Show the window.
    self.secondWindow.hidden = NO;
    }
}

- (void)setUpScreenConnectionNotificationHandlers
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
               name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
               name:UIScreenDidDisconnectNotification object:nil];
}

ADDITION:

Just tried to add code in ViewDidLoad

Added this:

// Check for external screen.
if ([[UIScreen screens] count] > 1)
{

}
else {
}

Have the opened external display and simulator - does't enter the IF block


Solution

  • The problem was in beta versions of OS and Xcode. Downgraded back to Maverics - and all works like a charm