为了检测 iOS11 屏幕录制功能的开或关,我使用了 isCaptured 和 UIScreenCapturedDidChange Notification。
当我第一次启动应用程序并在 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)")
}
在这种情况下,我需要终止该应用程序,清除缓存并再次启动该应用程序以获取屏幕录制事件。
请建议我可以在这里做些什么来检测录制事件以保护我的内容不被录制。
dim*_*mdy 13
斯威夫特 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)
    }
}
我想你总是可以检查这个变量,无论通知如何
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    let isCaptured = UIScreen.main.isCaptured
    return true
}
| 归档时间: | 
 | 
| 查看次数: | 6905 次 | 
| 最近记录: |