如何查看iOS11屏幕录像是打开还是关闭? [英] How to check iOS11 Screen Recording is On or Off?

查看:123
本文介绍了如何查看iOS11屏幕录像是打开还是关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了检测iOS11屏幕录制功能的开或关,我使用了isCaptured和UIScreenCapturedDidChange通知.

For detecting iOS11 screen recording feature On or Off I used isCaptured and UIScreenCapturedDidChange Notification.

第一次启动应用程序并在iOS11上内置屏幕录制功能时,它会以值True通知选择器方法,但是当我终止(终止)正在运行的应用程序并再次启动应用程序时,请再次执行相同的步骤,然后选择器方法没有被调用.

When first time I Launch the App and On iOS11 built-in screen recording feature then it notifies the selector method with value True, but when I kill (terminate) my running App and Launch app again do the same procedure again then my selector method is not getting called.

这是我的代码:

我在ViewWillAppear()方法中添加了一个观察者:

I add an Observer in ViewWillAppear() method:

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

选择器方法如下:

@objc
func handleNotification(notification:Notification){

    let isCaptured = UIScreen.main.isCaptured

    print("isCaptured value = \(isCaptured)")
}

在这种情况下,我需要终止该应用程序,清除缓存,然后再次启动该应用程序以获取屏幕录制事件.

In this case, I need to kill the app, clear the cache and again launch the app for getting screen recording event.

请建议我在这里可以执行哪些操作来检测录制事件,以保护我的内容免于录制.

Please suggest what I can do here to detect recording event to protect my content from recording.

推荐答案

Swift 4

添加观察者

UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)

接收更改

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
    if (keyPath == "captured") {
        let isCaptured = UIScreen.main.isCaptured

        print(isCaptured)
    }
}

这篇关于如何查看iOS11屏幕录像是打开还是关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆