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)
  }
}
Share:
899
Saayeed M Daawoud
Author by

Saayeed M Daawoud

Updated on January 04, 2023

Comments

  • Saayeed M Daawoud
    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

    Screen Record

  • Saayeed M Daawoud
    Saayeed M Daawoud almost 2 years
    please, check the question title! I'm asking for iOS, not for android
  • Saayeed M Daawoud
    Saayeed M Daawoud almost 2 years
    I'm asking about iOS not android