Matt February 2016

iPad airplay display shows black screen when I create a new UIWindow

[EDIT] I restarted the iPad and it fixed the issue. I'm leaving it here because stack overflow discouraged deleting the question

I have a weird thing happening on iPad Air 2. Using the method mentioned in https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html

I create a new UIWindow object for the secondary display connected through AirPlay.

- (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;

    NSLog(@"Show external window");
    // Set up initial content to display...
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]];
    UIViewController *controller = [storyboard instantiateInitialViewController];
    self.secondWindow.rootViewController = controller;
    // Show the window.
    self.secondWindow.hidden = NO;
   }

}

When I run this code on an iPhone 5s, The code works perfectly and the secondary window is initialized. However, when I run this code from Xcode on the iPad Air 2, I only see a black screen. If the app is not run through Xcode, the app launches on the iPad but on the AirPlay display it only shows the home screen with the app icon highlighted. The audio is still routed through AirPlay.

Any help would be greatly appreciated.

Answers


Shehzad Ali February 2016

Normally we change our UIWindow Color like this:

[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];

You can set your self.secondWindow color as:

secondWindow.backgroundColor = [UIColor whiteColor];


Matt February 2016

This was a ridiculous case and the solution to it was just as ridiculous. I restarted the iPad and the issue went away.

Post Status

Asked in February 2016
Viewed 3,981 times
Voted 12
Answered 2 times

Search




Leave an answer