Prevent screen capture in an iOS app

IosScreenshot

Ios Problem Overview


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.

Is it possible somehow in iOS to prevent screen capture?

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?

Ios Solutions


Solution 1 - Ios

I've just wrote simple extension of UIView that allows to hide it from screen-capturing, Airplay mirroring and so on. The solution uses ability of UITextField to hide a password from capturing.

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

using:

class ViewController: UIViewController {

   var secureView: UIView!

   override func viewDidLoad() {
      super.viewDidLoad()

      secureView.makeSecure()
   }
}

I'll be grateful if someone explains how Apple does this magic inside.

Solution 2 - Ios

There's no way to prevent taking screenshots entirely. You can do what Snapchat does, 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.

More details: https://stackoverflow.com/questions/13484516/ios-detection-of-screenshot

Solution 3 - Ios

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.

Solution 4 - Ios

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

In swift 4 add this code to your app delegate.

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

Solution 5 - Ios

I've heard that you can listen for a screenshot event using 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?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzolioView Question on Stackoverflow
Solution 1 - IosorakullView Answer on Stackoverflow
Solution 2 - IosJoshua GrossView Answer on Stackoverflow
Solution 3 - IosOnur ÇevikView Answer on Stackoverflow
Solution 4 - IosOurangZeb KhanView Answer on Stackoverflow
Solution 5 - IoslxknvlkView Answer on Stackoverflow