I'm toying with AirPlay using an iPhone 4S and I'm having some trouble. I've updated my Apple TV 2 to the latest (4.4.3 I think? I forget, it's in the other room and I'm too lazy to check) and I have iOS 5.0 on my 4S while I use Xcode 4.2 Build 4D199. I wrote a simple UIView app that attempts to draw on a second screen when available. Here's what I have in my viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:[[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]];
NSLog(@"Registering for screen connect events...");
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(screenDidConnect:)
name:UIScreenDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(screenDidDisconnect:)
name:UIScreenDidDisconnectNotification
object:nil]; NSLog(@"There are %i connected screens.", ScreenCount);
if (ScreenCount > 1) {
self.secondWindow = [self myScreenInit:[[UIScreen screens] objectAtIndex:1]];
[self.secondWindow addSubview:[self createFullscreenViewForText:@"Second window" withSize:CGSizeMake(640, 480)]];
}
}
This code works in the simulator when I enable TV Out although it always crashes if I enable TV Out while in debug. I have to relaunch the app after enabling TV out in the hardware menu in the simulator. On relaunch I see the second screen UILabel on the second screen. On the iPhone 4S I can only make this work if I enable AirPlay using the AirPlay control in the running tasks bar all the way to the left. You'll note that I have added an MPVolumeView component to the view on launch which I attempt to use to connect to my Apple TV to no avail.
If I use the in app MPVolumeView I can successfully disconnect from the Apple TV but when I use it again and select the apple TV to reconnect I do not get the UIScreenDidConnectNotification. Again the only time I can see the 2nd screen is when I enable mirroring. If I connect with either AirPlay control I only count 1 screen and never get the notification. Also, each time I enable mirroring I see this in the console logs:
Could not find mapped image ColorOnGrayShadow_AirPlay.png
This seems to be broken and I would like to know what others experience has been in this area. I'll continue to toy around and update this post as I learn new things.