【问题标题】:How to differentiate apple tv and other devices in airplay?如何在airplay中区分apple tv和其他设备?
【发布时间】:2016-03-08 09:38:11
【问题描述】:

我正在尝试通过 Airplay 连接 Apple tv,但如果我连接任何其他外部设备(如蓝牙)或其他设备,它显示为窗口中连接的设备,则问题是有一段时间了。所以我想确定连接了哪个设备,只有在连接 Apple tv 时才需要启用。

我如何识别它是 Apple tv 还是其他设备?

这就是我创建 Airplay 自定义按钮的方式

  for (UIButton *button in volumeView.subviews) {
            if ([button isKindOfClass:[UIButton class]]) {
                self.airplayButton = (UIButton*)button;
                button.frame = CGRectMake(0, 0, 30, 23);
                button.backgroundColor = [UIColor clearColor];
                [self.airplayButton addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];

            }

        }

因此,即使连接了其他一些设备,按钮的 alpha 值也总是会发生变化。

【问题讨论】:

    标签: ios xcode airplay apple-tv


    【解决方案1】:

    我以前看过这个,没有简单的方法来确定连接的设备是否是 Apple TV,有一个 Airplay Picker 可以做到这一点,但它背后的代码/功能似乎不是可用。

    您能做到的最好的方法是监视添加/删除的其他屏幕,然后仅在屏幕能够执行您需要的操作时才显示您的外部内容。

    我之前在某处读到过,您可以获得播放设备的功能并使用此信息来检测 Apple TV,但不幸的是,我目前找不到它。如果我找到它,我会添加评论。

    目前,您最好的选择是使用guide 中描述的概念

    提供的代码是在objective-c中,但它很容易转换为swift,这是你应该看的主要部分

    - (void)checkForExistingScreenAndInitializeIfPresent
    
    {
    
        if ([[UIScreen screens] count] > 1)
    
        {
    
            // Get the screen object that represents the external display.
    
            UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
    
            // Get the screen's bounds so that you can create a window of the correct size.
    
            CGRect screenBounds = secondScreen.bounds;
    
    
    
            self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
    
            self.secondWindow.screen = secondScreen;
    
    
    
            // Set up initial content to display...
    
            // Show the window.
    
            self.secondWindow.hidden = NO;
    
        }
    
    }
    

    就像我说的那样,您可以对此进行编码,以便它检查设备是否支持某些分辨率,这样您就可以排除不支持您的 UI 的设备

    一些额外的资源:@​​987654322@

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      相关资源
      最近更新 更多