简体   繁体   English

IOS iMessage扩展截图检测

[英]IOS iMessage extension screenshot detection

Please use Swift 4+ 请使用Swift 4+

NOTE: I am detecting the screenshot while I am within the iMessage extension, not in the standard iMessage view. 注意:当我在iMessage扩展中时,我正在检测屏幕截图,而不是在标准的iMessage视图中。

Update - I came up with a working solution that checks the photo library during the sensitive information period every .3 seconds or so to check if a new screenshot has been added. 更新 - 我想出了一个工作解决方案,每隔0.3秒左右检查敏感信息期间的照片库,以检查是否添加了新的屏幕截图。 If the user does not give permission to the photo library, it won't show them the content until they enable it. 如果用户未授予照片库的权限,则在启用照片库之前,它不会向其显示内容。 However, I am still looking for other creative solutions that don't necessarily involve such a tedious process. 但是,我仍然在寻找其他创造性的解决方案,而这些解决方案并不一定涉及如此繁琐的过程。

I have an iMessage extension and I am trying to detect screenshots. 我有一个iMessage扩展,我正在尝试检测截图。 I have tried every observer I have found online and for some reason it is not registering screenshots. 我已经尝试过我在网上找到的每一位观察者,但出于某种原因,它没有注册截图。

ViewWillAppear() viewWillAppear中()

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

Observer 观察

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
    if (keyPath == "captured") {
        let isCaptured = UIScreen.main.isCaptured
        print(isCaptured)
        screenshot()
        //screenshot() sends a message alerting the message was screens hotted. However, the print statement didn't even run.
    }
}

ViewWillDisappear() ViewWillDisappear()

UIScreen.main.removeObserver(self, forKeyPath: "captured", context: nil)

I have also tried the standard default Notification Center 我也尝试过标准的默认通知中心

let mainQueue = OperationQueue.main
    NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
        // executes after screenshot
        print("Screenshotted")
        self.screenshot()
    }

For people who claim it is not possible to detect screenshots within an iMessage extension because it is an extension and not a full app, this developer has been able to successfully do it Working Example 对于声称无法在iMessage扩展中检测屏幕截图的人,因为它是扩展而不是完整的应用程序,此开发人员已成功完成此工作示例

也许它有点过分,但您可以在受DRM保护的视频和系统中转换您的图像,防止任何屏幕截图/屏幕共享/屏幕录制受DRM保护的视频。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM