2

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)

Mr Phuc 87
  • 184
  • 2
  • 7

1 Answers1

5

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];
Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
  • Additionally, you cannot enable AirPlay mirroring from within your app. http://stackoverflow.com/questions/8786080/how-can-i-turn-on-airplay-screen-mirroring-on-the-iphone-4s-programmatically – Steven Stefanik Aug 26 '12 at 21:43