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?