防止在 iOS 应用中截屏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18680028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:01:11  来源:igfitidea点击:

Prevent screen capture in an iOS app

iosscreenshot

提问by zolio

I need to prevent screen capture by users of my app, for security reasons. The contents I display are confidential and should not be copied onto the device. I saw one answer on Stack Overflow, but for Android.

出于安全原因,我需要防止我的应用程序的用户截屏。我显示的内容是机密的,不应复制到设备上。我在 Stack Overflow 上看到了一个答案,但对于 Android

Is it possible somehow in iOS to prevent screen capture?

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

While capturing the screenshot into the gallery by the click of few buttons is a very useful feature for the user, there is a limited requirement to prevent it too. Any pointers?

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

回答by Joshua Gross

There's noway to prevent taking screenshots entirely. You can do what Snapchatdoes, which is by requiring the user to be touching the screen to view whatever information you're displaying. This is because the system screenshot event interrupts touches. It's not a perfect method and you can't prevent users from taking screenshots 100% of the time.

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

More details: iOS Detection of Screenshot?

更多细节:iOS检测截图?

回答by JimBobBennett

The other problem is screen capture in wetware - as in a person captures the screen with another device such as a camera or other phone. Even if you prevent it in the app it's impossible to prevent someone taking a photo of the screen

另一个问题是湿件中的屏幕捕获 - 就像一个人用其他设备(如相机或其他手机)捕获屏幕一样。即使您在应用程序中阻止它,也不可能阻止某人拍摄屏幕照片

回答by Ismail Degani

One possible workaround is Yovo. I just saw this demo which blew my mind!

一种可能的解决方法是Yovo。我刚刚看到这个演示让我大吃一惊!

http://vimeo.com/108244650

http://vimeo.com/108244650

It's an extremely clever way to obscure screenshot, and even partially handles the "wetware" case brought up by JimBobBennet.

这是一种隐藏屏幕截图的非常聪明的方法,甚至可以部分处理 JimBobBennet 提出的“湿件”案例。

You set up a blur mask on top of the image (fence pattern is used in the app, but any pattern will do) and move it as a fast rate. If the user takes a screenshot, they get the still image of a single frame, which by itself is obscured.

您在图像顶部设置了一个模糊蒙版(应用程序中使用了围栏图案,但任何图案都可以)并快速移动它。如果用户截取屏幕截图,他们将获得单帧的静止图像,该图像本身是模糊的。

It uses the fact that our brains can piece together an image behind a moving mask - similar to how you can "see-through" the blades of a moving fan.

它利用了这样一个事实,即我们的大脑可以将移动的面具后面的图像拼凑在一起——类似于您如何“透视”移动的风扇的叶片。

In order to capture the image, you would need to record a video of it, which is quite a hassle.

为了捕获图像,您需要录制它的视频,这非常麻烦。

The only issue here might be IP - Yovo claims to have 300+ patents...

这里唯一的问题可能是知识产权——Yovo 声称拥有300 多项专利......

回答by Ourang-Zeb Khan

Remove sensitive information from views before moving to the background. When an application transitions to the background, the system takes a snapshot of the application's main window, which it then presents briefly when transitioning your application back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.

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

In swift 4 add this code to your app delegate.

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

Declare a variable in app delegate

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

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.
    }

回答by Onur ?evik

It's been a while, but I just came across ScreenShieldKit, which is a patent-pending technology used by the messaging app Confide. What it does is that it let's the user take screenshots, but the content is blank on the end picture. They recently released the iOS version.

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

回答by lxknvlk

I've heard that you can listen for a screenshot event using UIApplicationUserDidTakeScreenshotNotification

我听说您可以使用 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];
                                              }];

what if you could immediately delete the screenshot file when it was made?

如果您可以在制作屏幕截图文件时立即将其删除怎么办?