2017-08-08 55 views
2

我們正在構建一個iOS應用程序,用戶可以在訂閱模型下觀看視頻。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然後啓動應用程序,則不會檢測到任何內容。

我需要檢測應用程序啓動時是否啓用鏡像。我見過其他應用程序這樣做,所以我相信這是可能的。

請幫忙。

回答

2

試試這個解決方案。

- (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; 
} 
+0

嗨Ganesh。謝謝您的幫助。此代碼正在工作! :) –

+0

嗨Ganesh。在最新的iOS 11中,屏幕錄製功能就在那裏。當我使用以下命令打開應用程序後開始錄製時,我可以檢測到它:UIScreenCapturedDidChangeNotification。但是,如果我先開始錄製然後打開應用(類似於上面分享的代碼),是否有任何方法可以檢測到它?謝謝您的幫助! –

+0

檢查了這一點https://stackoverflow.com/questions/46217459/how-to-understand-if-device-screen-is-being-recorded-in-ios-11/46218452#46218452 –

相關問題