AirPlay App To Apple TV Fullscreen With Controls on iPhone

In my app, there is one small section that displays lyrics to songs (PDFs loaded in a WKWebView). What I want to be able to do, is have a button to mirror that screen to an Apple TV, still control it with the iPhone/iPad, but have it be the full screen, optimized for a TV display. To get going, I have just added a property for a secondWindow UIWindow in AppDelegate, just to test out a few things. The code below is all I have added. It does work well with showing the full contents of the app on the TV, without any black borders, but when I do this, the screen on my iPhone is just completely white. I know the reason for this is because I set the root controller of the 2nd Window to navController which is set up in XIB, and would normally be the root view controller of the iPhone app. I guess what I need to know, is there a way I can simply copy the navController for use with the other UIWindow? Or is there a better way, since all I really need mirrored is on one view that's buried further down inside the hierarchy?

At the end of the day, all I really need is to on ONE view, if it detects AirPlay screen, move the WKWebView to the AirPlay device, at full screen, add 4 buttons to phone screen (to navigate through the PDFs next screen, previous screen, next file, previous file) and then put everything back on the phone screen when swiping back to the table view where the choose the initial PDF

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 

    window.rootViewController = navController;

    [window makeKeyAndVisible];

    if ([UIScreen screens].count > 1) {
            [self setUpSecondWindowForScreen:[UIScreen screens][1]];
          }
    
          NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
          [center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
                         name:UIScreenDidConnectNotification object:nil];
          [center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
                         name:UIScreenDidDisconnectNotification object:nil];
        
    }
    
    - (void)handleScreenDidConnectNotification:(NSNotification*)notification {
      if (!self.secondWindow) {
        [self setUpSecondWindowForScreen:[notification object]];
      }
    }
    
    - (void)handleScreenDidDisconnectNotification:(NSNotification*)notification {
      if (self.secondWindow) {
        self.secondWindow = nil;
      }
    }
    
    - (void)setUpSecondWindowForScreen:(UIScreen*)screen {
      self.secondWindow = [[UIWindow alloc] init];
      self.secondWindow.screen = screen;
      self.secondWindow.screen.overscanCompensation = UIScreenOverscanCompensationNone;
    
      UIViewController *viewController = [[UIViewController alloc] init];
      viewController.view.backgroundColor = [UIColor redColor];
      self.secondWindow.rootViewController = navController;
    
      [self.secondWindow makeKeyAndVisible];
    }

Replies

Anyone?