Created
September 16, 2021 18:36
-
-
Save mmdock/dc9af067f892c0ea0860136758664a48 to your computer and use it in GitHub Desktop.
Prevent screencapture / recordings on iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only tested on iOS 14.
Need to test on older iOS versions and the new iOS 15