Skip to content

Instantly share code, notes, and snippets.

@mmdock
Created September 16, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmdock/dc9af067f892c0ea0860136758664a48 to your computer and use it in GitHub Desktop.
Save mmdock/dc9af067f892c0ea0860136758664a48 to your computer and use it in GitHub Desktop.
Prevent screencapture / recordings on iOS
extension UIView {
/// secure a view to prevent it appearing in screenshots or screen recordings
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)
}
}
}
@mmdock
Copy link
Author

mmdock commented Sep 16, 2021

Only tested on iOS 14.

Need to test on older iOS versions and the new iOS 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment