如何在第二个屏幕上使用iOS 5+ AirPlay

Cli*_*iff 2 airplay ios5 apple-tv

我正在使用iPhone 4S玩AirPlay,我遇到了一些麻烦.我已经将我的Apple TV 2更新到最新版本(4.4.3我认为?我忘记了,它在另一个房间里,我懒得检查)我在4S上使用iOS 5.0而我使用的是Xcode 4.2 Build 4D199 .我写了一个简单的UIView应用程序,试图在可用时在第二个屏幕上绘制.这是我在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)]];
    }
}
Run Code Online (Sandbox Code Playgroud)

当我启用TV Out时,此代码在模拟器中工作,但如果我在调试时启用TV Out,它总是会崩溃.我必须在模拟器的硬件菜单中启用电视输出后重新启动应用程序.重新启动时,我在第二个屏幕上看到第二个屏幕UILabel.在iPhone 4S上,如果我使用正在运行的任务栏中的AirPlay控件一直向左启用AirPlay,我只能进行此操作.你会注意到我在启动视图中添加了一个MPVolumeView组件,我尝试使用它来连接到我的Apple TV无济于事.

如果我使用in app MPVolumeView我可以成功断开Apple TV,但当我再次使用它并选择Apple TV重新连接时,我没有得到UIScreenDidConnectNotification.我唯一能看到第二个屏幕的时候是我启用镜像的时候.如果我使用AirPlay控件连接,我只计算1个屏幕并且从不接收通知.此外,每次启用镜像时,我都会在控制台日志中看到:

Could not find mapped image ColorOnGrayShadow_AirPlay.png
Run Code Online (Sandbox Code Playgroud)

这似乎被打破了,我想知道其他人在这个领域的经历.当我学习新东西时,我会继续玩弄并更新这篇文章.

que*_*ish 5

MPVolumeView的路由菜单只能控制进入AppleTV的音频流.以下是您尝试执行的操作示例:https: //github.com/quellish/AirplayDemo/

对于iOS 5,"ColorOnGrayShadow_AirPlay.png"日志消息是正常的.使用Airplay连接的AppleTV作为外部显示器不幸需要镜像,并且您无法从应用程序内部激活它.用户必须遵循以下说明:

http://support.apple.com/kb/TS4085