Restrict screenshot in iOS app

I am trying to restrict screenshot from my running iOS application. I have found following workaround:

private extension UIView {
    func setScreenCaptureProtection() {
        guard superview != nil else {
            for subview in subviews { 
                subview.setScreenCaptureProtection()
            }
            return
        }

        let guardTextField = UITextField()
        guardTextField.backgroundColor = .clear
        guardTextField.translatesAutoresizingMaskIntoConstraints = true
        guardTextField.isSecureTextEntry = true
        addSubview(guardTextField)
        guardTextField.isUserInteractionEnabled = false
        sendSubviewToBack(guardTextField)
        layer.superlayer?.addSublayer(guardTextField.layer)
        guardTextField.layer.sublayers?.first?.addSublayer(layer)
        guardTextField.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
        guardTextField.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true
        guardTextField.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true
        guardTextField.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 0).isActive = true
    }

I am trying to achieve it in Ionic, hence, I set setScreenCaptureProtection to root controller view in app delegate. However, it disables the interaction of the view.

Do we have any other solution to prevent screenshot or can we have interaction with above solution?

There is no intended functionality to prevent a screenshot – screenshots are a user controlled feature intended to always be available. Consider that a sufficiently motivated user will simply use another device to take a picture of the screen and you cannot prevent that. Similarly by forcing a user to do that your creating a less secure situation, as the image will now be on 2 devices instead of 1 and will be harder for the user to maintain control over.

Additionally the code you use above is going behind UIKit to add a view's layer to another view's layer – this will cause subtle and not to subtle issues depending on exactly what your app ends up doing – it may even be the cause of your interaction issues. UIViews are intended to only be added to other views via addSubivew() and related methods, not via their layers.

Above code works well for only see only views. Fails when applied directly to self.view incase of tableview , scrolling happens but did select not gets called !!

Restrict screenshot in iOS app
 
 
Q