2016-08-02 108 views

回答

3

因此不知道檢測QuickTime Player的錄音。

但我找到了一些解決方案。

如果QuickTime Player錄音正在運行,AVAudioSession的輸出portType已更改爲HDMIOutput。

所以我編碼如下...(雨燕2.2)

func checkOutputPortType() { 
    let asRoute = AVAudioSession.sharedInstance().currentRoute 
    for output in asRoute.outputs { 
     if output.portType == AVAudioSessionPortHDMI { 
      // something you want.. 
     } 
    } 
} 

插入,在viewDidLoad中發揮作用,並添加AVAudioSessionRouteChangeNotification通知。

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(checkOutputPortType), name: AVAudioSessionRouteChangeNotification, object: nil) 

謝謝。

0

與iOS 11,你可以使用通知

NSNotification.Name.UIScreenCapturedDidChange 

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    NotificationCenter.default.addObserver(self, selector: #selector(checkIFScreenIsCapture), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil) ...... 

使用選擇

func checkIFScreenIsCapture(notification:Notification){ 
    guard let screen = notification.object as? UIScreen else { return } 
    if screen.isCaptured == true { 

    }else{ 

    } 
}