Question

I'm trying to display a picture on Apple TV with Airplay without mirroring mode. But [UIScreen screens] method always return 1 screen (main screen) when mirroring is OFF. I want my picture display same as Photo application (Airplay without mirroring).

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];

I used them, but they only work when Mirroring is ON.

Please help me. Thanks so much! I'm using Apple TV1 and iPad 2 (iOS 5.0.1)

Was it helpful?

Solution

Well, it's a bit misleading, indeed. You should proceed as follows:

  • Airplay mirroring option should be ON
  • then, you create a new UIWindow and attach it to the second screen
  • as soon as you send makeKeyAndVisible to this new UIWindow, it overrides mirroring and shows new content.
  • You may add views or a root view controller as in the main part of application

Here's the code:

UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
self.secondWindow = [[UIWindow alloc] initWithFrame:secondScreen.bounds];
[self.secondWindow setScreen:secondScreen];
[self.secondWindow setBackgroundColor:[UIColor greenColor]];
[self.secondWindow makeKeyAndVisible];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top