【问题标题】:Prevent screen capture in an iOS app阻止 iOS 应用程序中的屏幕截图
【发布时间】:2013-09-11 20:49:11
【问题描述】:

出于安全原因,我需要阻止我的应用用户进行屏幕截图。我显示的内容是机密的,不应复制到设备上。我看到了one answer on Stack Overflow, but for Android。

是否有可能在 iOS 中以某种方式阻止屏幕捕获?

虽然通过单击几个按钮将屏幕截图捕获到图库中对用户来说是一项非常有用的功能,但也有一个有限的要求来阻止它。有什么指点吗?

【问题讨论】:

  • 这是一个操作系统级别的操作,所以我认为这是不可能的,除非您在越狱设备上运行。不过我可能是错的。
  • 我不认为你可以在非越狱设备上阻止它,但你可以检测到它 - stackoverflow.com/questions/13484516/…
  • 另一个问题是湿件中的屏幕捕获 - 就像一个人使用其他设备(例如相机或其他电话)捕获屏幕一样。即使您在应用程序中阻止它,也无法阻止有人对屏幕拍照
  • 有什么方法可以检测到块中捕获的图像,我们可以让它变得模糊吗?
  • 我已经看到了一些这样做的安全框架,但我不知道它们具体是做什么的,但肯定有一些系统调用拦截。

标签: ios screenshot


【解决方案1】:

我刚刚编写了 UIView 的简单扩展,允许将其从屏幕捕获、Airplay 镜像等中隐藏起来。该解决方案使用 UITextField 的功能来隐藏密码以防止捕获。

extension UIView {
    func makeSecure() {
        DispatchQueue.main.async {
            let field = UITextField()
            field.isSecureTextEntry = true
            self.addSubview(field)
            field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
            field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
            self.layer.superlayer?.addSublayer(field.layer)
            field.layer.sublayers?.first?.addSublayer(self.layer)
        }
    }
}

使用:

class ViewController: UIViewController {

   var secureView: UIView!

   override func viewDidLoad() {
      super.viewDidLoad()

      secureView.makeSecure()
   }
}

如果有人解释 Apple 如何在内部发挥这种魔力,我将不胜感激。

【讨论】:

  • 这有点像魔术,但这种方法确实有效!它与自动布局混淆了......知道如何解决它吗?
  • 另外,你的来源是什么?它似乎在互联网上没有提及
  • 另外需要注意的是,这只适用于iOS 13+
  • 这可能会导致几个问题,我建议不要这样做。如果您的图层还有其他子图层(例如自定义视图),那么这很可能会崩溃,具体取决于您的实现。
  • @orakull _UITextLayoutCanvasView 负责隐藏东西(见gist.github.com/damian-rzeszot/bbfd92895dfe9400ba9a7cf2a0c1e670)
【解决方案2】:

没有方法可以完全阻止截屏。您可以做 Snapchat 所做的事情,即要求用户触摸屏幕以查看您正在显示的任何信息。这是因为系统截图事件中断了触摸。这不是一个完美的方法,你不能阻止用户 100% 的时间截取屏幕截图。

更多详情:iOS Detection of Screenshot?

【讨论】:

  • 我不使用 Snapchat,所以我现在无法测试它,但是如果你将 iPhone 插入 Mac 并通过 Xcode 截屏会发生什么? (手指一直在屏幕上)。我很确定没有编程方式来检测(更不用说防止)这样的屏幕截图......
【解决方案3】:

已经有一段时间了,但我刚刚遇到了ScreenShieldKit,这是消息应用程序 Confide 使用的一项正在申请专利的技术。它的作用是让用户截取屏幕截图,但最终图片上的内容是空白的。他们最近发布了 iOS 版本。

【讨论】:

  • 它需要采用他们的自定义 UI 元素,因为它是通过使用 DRM 将视图转换为视频来保护的
  • @CameronLowellPalmer 你怎么知道他们在使用 DRM?
  • 如果你深入研究他们的二进制文件,你会发现他们正在做视频转码,整个事情是相当明显的。 Apple 为符合版权法的视频层提供保护。
【解决方案4】:

在移至视图之前从视图中删除敏感信息 背景。当应用程序转换到后台时, 系统拍摄应用程序主窗口的快照,它 然后在将您的应用程序转换回 前景。从您的 applicationDidEnterBackground 返回之前: 方法,您应该隐藏或隐藏密码和其他敏感信息 可能作为快照的一部分捕获的个人信息。

在 swift 4 中将此代码添加到您的应用委托。

在应用委托中声明一个变量

var imageview : UIImageView?

func applicationWillResignActive(_ application: UIApplication) {

        imageview = UIImageView.init(image: UIImage.init(named: "bg_splash"))
        self.window?.addSubview(imageview!)
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

func applicationDidBecomeActive(_ application: UIApplication) {
        if (imageview != nil){

            imageview?.removeFromSuperview()
            imageview = nil
        }
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

【讨论】:

  • 是的@AbdulYasin 请分享您的最佳解决方案
  • 其实iOS中并没有这样的防止截图的方法。虽然您可以使用第三方库。
  • 是的,除了隐藏你的信息之外别无他法,你放了一层图像,这样你的敏感信息就不应该传给用户,除此之外没有任何机制。
  • 这与问题无关
  • 此代码在 iOS 版本 13.3.1 的 xcode11.3 中不起作用
【解决方案5】:

我听说你可以使用 UIApplicationUserDidTakeScreenshotNotification 来监听截图事件

 NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
                                                  object:nil
                                                   queue:mainQueue
                                              usingBlock:^(NSNotification *note) {
                                                  // executes after screenshot
                                                  NSLog(@"Screenshot Detection : %@", note);
                                                  UIAlertView *screenshotAlert = [[UIAlertView alloc] initWithTitle:@"Screenshot Detected" message:@"Oh Oh no screenshot bruhh" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                                                  [screenshotAlert show];
                                              }];

如果您可以在截屏文件制作完成后立即删除它会怎样?

【讨论】:

  • 如何删除文件?这是不可能的 AFAIK。
  • 我对 ios 开发不是很熟悉,但在 android 上,如果用户允许访问图库,您可以从那里创建和删除文件。所以我想你可以立即删除截图。
  • 虽然这可能无法帮助您阻止屏幕截图,但它是跟踪是否有人在截屏以及问题在您的应用中的普遍程度的好方法。如果您的应用程序使用登录机制,您可以识别用户并限制应用程序访问或向用户提供通知(如果需要)。我在一个应用程序中实现了这一点,用户正在拍摄屏幕截图,但数量太少,无需努力阻止。
  • 如果该用户分享截取的屏幕截图怎么办?
  • @BadmintonCat 可以,但需要用户权限
猜你喜欢
  • 2020-02-13
  • 1970-01-01
  • 2019-11-24
  • 1970-01-01
  • 1970-01-01
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多