How to prevent/disable screenshots on iOS 17 beta ?

I want to disable taking screenshots of confidential information but it is not working in iOS 17 beta .

For earlier version I am using ‘isSecureTextEntry' but it is unstable for the recent beta . I am still able to detect the screenshot but not prevent it by using UIApplication.userDidTakeScreenshotNotification .

Is there any way to achieve it ?

Answered by bellabradhe in 765331022

Hi! I had the same issue, this is the function I use, I call it in the AppDelegate.

func makeSecure(window: UIWindow) {
        let field = UITextField()

        let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))

        let image = UIImageView(image: UIImage(named: "whiteImage"))
        image.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

        field.isSecureTextEntry = true

        window.addSubview(field)
        view.addSubview(image)

        window.layer.superlayer?.addSublayer(field.layer)
        field.layer.sublayers?.last!.addSublayer(window.layer)

        field.leftView = view
        field.leftViewMode = .always
    }

Before this version I had it in the first element and it worked well but now I had to add it to the last . I hope it helps you.

Can't you just detect it and hide the text. There is no way to prevent the screenshot even in the previous IOS16. The most you can do is detect it.

I think the question is whether when you do detect it, if there is enough time to hide the text before the screenshot is actually taken.

I'm facing the same issue. The problem even exists on iOS 17.0 release version. Does anyone have any solutions?

Accepted Answer

Hi! I had the same issue, this is the function I use, I call it in the AppDelegate.

func makeSecure(window: UIWindow) {
        let field = UITextField()

        let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))

        let image = UIImageView(image: UIImage(named: "whiteImage"))
        image.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

        field.isSecureTextEntry = true

        window.addSubview(field)
        view.addSubview(image)

        window.layer.superlayer?.addSublayer(field.layer)
        field.layer.sublayers?.last!.addSublayer(window.layer)

        field.leftView = view
        field.leftViewMode = .always
    }

Before this version I had it in the first element and it worked well but now I had to add it to the last . I hope it helps you.

@bellabradhe : This works for me for the hole screen. It's possible to prevent only an UIView or a SwiftUI View?

I call my screenshot protection function from an @IBInspectable and it worked for me to implement this change (attached before and after image) I added it to the view because if I added it to the window you will no longer be able to take a screenshot in nowhere in the app after the protection appears

before

after

How to prevent/disable screenshots on iOS 17 beta ?
 
 
Q