2016-08-02 73 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{ 

    } 
}