iOS应用启动时如何检测Airplay?

5
我们正在开发一款iOS应用程序,用户可以在订阅模式下观看视频。我们不希望用户将视频Airplay到任何其他设备。视频是在UIWebView中播放的。我查看了各种在线资源:
  1. https://developer.apple.com/documentation/uikit/uiwebview/1617973-mediaplaybackallowsairplay?language=objc

  2. https://github.com/MobileVet/AirPlayDetector

上述选项未起作用。 此外,我尝试了这段代码,但它总是返回1。
if ([[UIScreen screens] count] < 2)) {
//streaming
}
else {
//mirroring
}

我也尝试了这段代码:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveAirPlayNotification:) name: UIScreenDidConnectNotification object:nil];

当我启动应用程序并打开Airplay时,此通知系统才能正常工作。如果我先打开Airplay,然后再启动应用程序,则无法检测到任何内容。

我需要在应用程序启动时检测是否已启用镜像。我已经看到其他应用程序可以做到这一点,因此我相信这是可能的。

请帮忙。

1个回答

5
尝试使用这个解决方案。
- (BOOL)isAirplayOn
{
    AVAudioSession* audioSession = [AVAudioSession sharedInstance];
    AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute;
    for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){
        if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay])
            return YES;
    }
    return NO;
}

嗨 Ganesh。感谢你的帮助。这段代码正在运行!:) - Vitul Goyal
嗨 Ganesh。在最新的iOS 11中,有屏幕录制功能。我可以使用UIScreenCapturedDidChangeNotification在打开应用程序后开始录制时检测到它。但是,如果我先开始录制,然后再打开应用程序(类似于您上面分享的代码),是否有任何方法可以检测它?感谢您的帮助! - Vitul Goyal
请查看此链接 https://stackoverflow.com/questions/46217459/how-to-understand-if-device-screen-is-being-recorded-in-ios-11/46218452#46218452 - Ganesh Bavaskar
@GaneshBavaskar,您能够使用此功能或Airplay检测到镜像吗? - Ankit Kumar Gupta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接