【问题标题】:Programmatically disabling screenshot in App以编程方式禁用 App 中的屏幕截图
【发布时间】:2026-02-17 18:20:10
【问题描述】:

我想防止在应用程序中截取页面。 如何以编程方式进行,以便无法截取屏幕截图。

找到检测屏幕截图的代码。截屏后可以删除吗?

let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification,
    object: nil,
    queue: mainQueue) { notification in
        // executes after screenshot
}

【问题讨论】:

  • 没有办法,你可以用越狱检查
  • 如果您希望用户不能截屏,因为该特定页面上显示的敏感信息,您应该尝试另一种方式,因为这不是一个好习惯,即使在@雅各布·金的回答
  • 感谢大家的回复
  • 有可能,Amazon Prime Video 应用程序就是这样做的,如果你想截屏,你只会得到一个黑色的矩形。抱歉,我不知道如何以编程方式执行此操作,但无需访问照片库即可。
  • 有一个关于它的问题:*.com/questions/18680028/…

标签: swift


【解决方案1】:

没有办法阻止屏幕截图,但您可以阻止屏幕录制 通过这段代码。

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()")
    }
}

【讨论】:

    【解决方案2】:

    在应用过程中绝对没有办法完全阻止用户截图,这是因为您无权删除用户照片库中的照片。如果您可以访问用户的照片,那将完全是一个安全问题。


    但是,有一些方法可以部分阻止屏幕截图,如下所述:Prevent screen capture in an iOS app

    【讨论】:

    • 也没有办法阻止来自其他设备的屏幕截图!
    • @Russell 没错,你不能阻止用户从其他设备拍照
    【解决方案3】:

    技术上这是可能的,通过Photos 框架,可以找到here 的文档。

    示例代码可以在here找到。

    但是,这会先询问用户的权限,然后再确认删除;所以可能不是理想的解决方案。不幸的是,这与 Apple 已完全锁定相机胶卷一样好。

    【讨论】: