为了检测 iOS11 屏幕录制功能的开或关,我使用了 isCaptured 和 UIScreenCapturedDidChange Notification。
当我第一次启动应用程序并在 iOS11 内置屏幕录制功能上时,它会使用值 True 通知选择器方法,但是当我杀死(终止)正在运行的应用程序并再次启动应用程序时,再次执行相同的过程,然后我的选择器方法是没有被调用。
这是我的代码:
我在 ViewWillAppear() 方法中添加了一个观察者:
NotificationCenter.default.addObserver(self, selector: #selector(handleNotification), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)
Run Code Online (Sandbox Code Playgroud)
选择器方法如下:
@objc
func handleNotification(notification:Notification){
let isCaptured = UIScreen.main.isCaptured
print("isCaptured value = \(isCaptured)")
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我需要终止该应用程序,清除缓存并再次启动该应用程序以获取屏幕录制事件。
请建议我可以在这里做些什么来检测录制事件以保护我的内容不被录制。