How to prevent taking screen shoot in flutter IOS
899
Actually, APP Store Prevent this feature which is disable screenshot so we can work around to do this. my solution was to make user make an screen shot but with no data. I achieve it by this simple code
import UIKit
import Flutter
import FirebaseCore
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
private var textField = UITextField()
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.window.makeSecure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// Screenshot Prevent Functions
// <Add>
override func applicationWillResignActive(
_ application: UIApplication
) {
self.window.isHidden = true;
}
override func applicationDidBecomeActive(
_ application: UIApplication
) {
self.window.isHidden = false;
}
}
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)
}
}
Author by
Saayeed M Daawoud
Updated on January 04, 2023Comments
-
Saayeed M Daawoud over 1 year
I've got an education flutter iOS app. and I want to prevent users to take screenshots or screen records on a specific screen and how to make it
I'm trying many solutions here but no one is working
as attached below, it is a screen record form my iPhone from another app it still records till I reach to specific screen and push me back and showing me this alert dialog how to achieve this feature
-
flatasearth almost 2 yearsDoes this answer your question? How to disable screen Recording in iOS app
-
Andrew almost 2 yearsDoes this answer your question? Prevent screen capture in an iOS app
-
Saayeed M Daawoud almost 2 yearsno, I'm trying both and not working
-
-
Saayeed M Daawoud almost 2 yearsplease, check the question title! I'm asking for iOS, not for android
-
Saayeed M Daawoud almost 2 yearsI'm asking about iOS not android