2

In my iOS app I need to display custom content on external display (using AirPlay) as well as mirroring some screens on TV. For presenting custom content I use code from Multiple Display Programming Guide for iOS and it works well: while my iPad is in 'mirror' AirPlay mode I'm able to show some stuff on the TV. However, documentation says6

To re-enable mirroring after displaying unique content, simply remove the window you created from the appropriate screen object.

And this part isn't working at all. I just cannot destroy my window that I use to display content on external screen. Here's the code:

- (void) destroySecondWindow{
    if (secondWindow){
        for( UIView* view in secondWindow.subviews ){
            [view removeFromSuperview];
        }        
    
        secondWindow.backgroundColor = [UIColor clearColor];
        secondWindow.hidden = YES;
    
        // Hide and then delete the window.
        [secondWindow removeFromSuperview];
        secondWindow = nil;
    
    }
}

As far as unique content should be displayed only when one particular view controller is visible, I'm trying to destroy external window like this:

 - (void) viewWillDisappear:(BOOL)animated{
     [self destroySecondWindow];
 }

Here's how I create second window:

- (void) createSecondWindowForScreen:(UIScreen*)screen{
    if( screen == nil || secondWindow != nil ){
        return;
    }
    
    CGRect        screenBounds = screen.bounds;
    
    secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
    secondWindow.backgroundColor = [UIColor blueColor];
    secondWindow.screen = screen;

    [secondWindow setHidden:NO];
}

So the question is: does anybody know how to re-enable screen mirroring after displaying unique content on TV?

Thanks in advance!

Community
  • 1
  • 1
art-o-nawa
  • 329
  • 1
  • 12

0 Answers0