iOS AirPlay:我的应用程序仅在镜像开启时通知外部显示器? [英] iOS AirPlay: my app is only notified of an external display when mirroring is ON?

查看:191
本文介绍了iOS AirPlay:我的应用程序仅在镜像开启时通知外部显示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中启用AirPlay支持。我不是在做视频;我想将外接显示器用作第二显示器。

I'm trying to enable AirPlay support in my app. I'm not doing video; I want to use the external display as a "second display".

这是我的问题:如果我从AirPlay按钮选择AppleTV,我的应用程序无法获得收到通知。我的应用程序获得通知的唯一一次是当我离开我的应用程序时,转到操作系统级别的AirPlay按钮,在那里选择AppleTV并打开镜像。如果我关闭镜像,我的应用程序会被告知外部显示器已经消失。

Here's my problem: if I choose "AppleTV" from my AirPlay button, my app doesn't get notified. The only time my app -does- get notified is when I leave my app, go to the OS-level AirPlay button, choose "AppleTV" there and turn on Mirroring. If I turn mirroring off, my app is then told that the external display is gone.

所以:


  1. 当我在我的应用程序中从
    选择外部显示器时,为什么我的应用程序不会收到通知?

  2. 为什么我的应用程序会收到通知当我开启镜像时...而不是之前的
    外部显示器?我显然误解了一些东西,但看起来像镜像应该通知我的应用程序外部显示器已经消失(而不是现在可用,因为操作系统现在应该使用外部显示器进行镜像。)

下面的代码示例。预先感谢您的帮助!

Code sample below. Thanks in advance for any help!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

     // Override point for customization after application launch.

     // Is there already an external screen?
     if (UIScreen.screens.count > 1)]
     {
          [self prepareExternalScreen:UIScreen.screens.lastObject];
     }

     // Tell us when an external screen is added or removed.
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidConnect:) name:UIScreenDidConnectNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];

     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
     self.window.rootViewController = self.viewController;

     // Add AirPlay control to view controller.
     MPVolumeView* airplayButtonView = [[MPVolumeView alloc] init];
     airplayButtonView.frame = CGRectMake(300, 300, 50, 50);
     airplayButtonView.backgroundColor = [UIColor blackColor];
     airplayButtonView.showsVolumeSlider = NO;
     airplayButtonView.showsRouteButton = YES;

     [self.viewController.view addSubview:airplayButtonView];


    [self.window makeKeyAndVisible];

    return YES;
}

#pragma mark - External screen handling

- (void)externalScreenDidConnect:(NSNotification*)notification
{
     [self prepareExternalScreen:notification.object];
}

- (void)externalScreenDidDisconnect:(NSNotification*)notification
{
     // Don't need these anymore.
     self.externalWindow = nil;
}

- (void)prepareExternalScreen:(UIScreen*)externalScreen
{
     NSLog(@"PREPPING EXTERNAL SCREEN.");
     self.viewController.view.backgroundColor = [UIColor blueColor];
     CGRect frame = externalScreen.bounds;
     self.externalWindow = [[UIWindow alloc] initWithFrame:frame];
     self.externalWindow.screen = externalScreen;
     self.externalWindow.hidden = NO;
     self.externalWindow.backgroundColor = [UIColor redColor];
}


推荐答案

不幸的是,这是正确的。辅助显示(airplay屏幕)仅适用于镜像。

That's correct, unfortunately. The secondary display (the airplay screen) is only available with mirroring.

这是一个显示如何实现此功能的应用程序:
https://github.com/quellish/AirplayDemo

Here is an application that shows how to implement this: https://github.com/quellish/AirplayDemo

查看代码,你应该是当用户进入播放菜单并在您的应用处于活动状态时打开镜像时获取UIScreenDidConnectNotification。 MPVolumeView或电影控制器的Airplay按钮不控制镜像(因此也不控制外部显示功能)。不幸的是,视频和音频输出与镜像分开,只能使用系统范围的镜像UI打开或关闭镜像。

Looking at your code, you SHOULD be getting the UIScreenDidConnectNotification when a user goes to the airplay menu and turns on mirroring while your app is active. The "Airplay Button", wether a MPVolumeView or movie controller, does not control mirroring (and thus the external display functionality). Video and audio out are unfortunately separate from mirroring, and mirroring can only be turned on or off using the system wide mirroring UI.

底线:你无法打开您的应用内的AirPlay屏幕。

Bottom line: You can't turn on that AirPlay screen from within your app.

这篇关于iOS AirPlay:我的应用程序仅在镜像开启时通知外部显示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆