I have a flutter
app where I want to prevent users from taking screenshots and screen recordings. I have the following code which perfectly works for ios
version lower than 17 but not for ios 17
AppDelegate
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
setUpBlurEffectView()
NotificationCenter.default.addObserver(self, selector: #selector(toggleScreenBlurForCapture), name: UIScreen.capturedDidChangeNotification, object: nil)
window?.makeSecure()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func setUpBlurEffectView() {
let blurEffect = UIBlurEffect(style: .regular)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView?.frame = window?.bounds ?? UIScreen.main.bounds
blurEffectView?.isHidden = true
window?.addSubview(blurEffectView!)
}
@objc func toggleScreenBlurForCapture() {
let isCaptured = UIScreen.main.isCaptured
blurEffectView?.isHidden = !isCaptured
}
extension UIWindow {
func makeSecure() {
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)
}
}
What am I doing wrong here? Has something changed on ios 17
? Any hint or help would be appreciated.
2
Answers
replace this
to this
use screen_protector package as it’s not possible to prevent the screenshotting on iOS but you can make the user screenshot a black screen instead of your content using the package i mentioned above.