【问题标题】:iOS detect Airplay during app launchiOS 在应用启动期间检测 Airplay
【发布时间】:2018-01-15 11:37:42
【问题描述】:

我们正在构建一个 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 然后启动应用程序,则没有检测到任何东西。

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

请帮忙。

【问题讨论】:

    标签: ios objective-c iphone uiwebview


    【解决方案1】:

    试试这个解决方案。

    - (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。谢谢您的帮助。这段代码有效!! :)
    • 嗨,Ganesh。在最新的 iOS 11 中,有屏幕录制功能。打开应用程序后开始录制时,我可以检测到它:UIScreenCapturedDidChangeNotification。但是,如果我先开始录制然后打开应用程序(类似于您在上面共享的代码),有什么方法可以检测到它?感谢您的帮助!
    猜你喜欢
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 2010-09-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-19
    相关资源
    最近更新 更多