UIScreen screens always return 1 screen
Asked Answered
L

1

1

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)

Lindgren answered 9/7, 2012 at 8:59 Comment(0)
G
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];
Gauge answered 20/8, 2012 at 19:37 Comment(1)
Additionally, you cannot enable AirPlay mirroring from within your app. #8786580Quieten

© 2022 - 2024 — McMap. All rights reserved.