我想防止在应用程序中截取页面的屏幕截图。如何以编程方式进行操作,以便无法截取屏幕截图。
找到代码来检测屏幕截图。截图后可以删除吗?
let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification,
object: nil,
queue: mainQueue) { notification in
// executes after screenshot
}
Run Code Online (Sandbox Code Playgroud)
小智 11
无法阻止屏幕截图,但您可以通过此代码阻止屏幕录制。
func detectScreenRecording(action: @escaping () -> ()) {
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: UIScreen.capturedDidChangeNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
//Call in vewWillApper
detectScreenRecording {
print(UIScreen.main.isCaptured)
if UIScreen.main.isCaptured {
//your vier hide code
print("self.toHide()")
} else {
// self.sceneDeleg(ate?.window?.isHidden = false
//your view show code
print("self.toShow()")
}
}
Run Code Online (Sandbox Code Playgroud)
绝对没有办法完全阻止用户在应用程序过程中截图,这是因为您无权删除用户照片库中的照片。如果您可以访问用户的照片,那将完全是一个安全问题。
但是,有一些方法可以部分阻止屏幕截图,如下所述:Prevent screen capture in an iOS app
| 归档时间: |
|
| 查看次数: |
29169 次 |
| 最近记录: |