iOS detect/block screen recording using QuickTime player

三世轮回 提交于 2019-12-03 09:15:50

Thus don't know detect QuickTime Player recording.

But I Found a solution with some trick.

If QuickTime Player recording is running, AVAudioSession's output portType has been changed to HDMIOutput.

So I coding as follows...(Swift 2.2)

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

Insert that function in ViewDidLoad and added AVAudioSessionRouteChangeNotification notification.

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

Thanks.

With iOS 11 you can use the notification

NSNotification.Name.UIScreenCapturedDidChange

on AppDelegate.swift

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

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

use selector

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

    }else{

    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!