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 ?

Accepted Reply

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.

  • Hi @bellabradhe for my end its working but problem is that if i attempt to take Screenshot just after launch of applications its allow to take then i try for next time its not allow it what could be reason .

  • im curious, why it is work, is there any update in ios 17 that affect the queue (first, and last) layer?

  • This works like magic, thanks!

Add a Comment

Replies

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.

Add a Comment

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

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.

  • Hi @bellabradhe for my end its working but problem is that if i attempt to take Screenshot just after launch of applications its allow to take then i try for next time its not allow it what could be reason .

  • im curious, why it is work, is there any update in ios 17 that affect the queue (first, and last) layer?

  • This works like magic, thanks!

Add a Comment

@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

  • is there a way to not to be able to take screenshot nowhere except two screens for example?

Add a Comment