为了检测 iOS11 屏幕录制功能打开或关闭,我使用了 isCaptured 和 UIScreenCapturedDidChange 通知。
当我第一次启动应用程序并在 iOS11 上内置屏幕录制功能时,它会通知选择器方法值为 True,但是当我终止(终止)我正在运行的应用程序并再次启动应用程序时,再次执行相同的过程然后我的选择器方法未被调用。
这是我的代码:
我在 ViewWillAppear() 方法中添加了一个观察者:
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)")
}
在这种情况下,我需要终止该应用程序,清除缓存并再次启动该应用程序以获取屏幕录制事件。
请建议我在这里可以做什么来检测录制事件以保护我的内容不被录制。
最佳答案
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)
}
}
关于ios - 如何查看iOS11录屏是开还是关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46232701/