ios

xcode - Runner-AppDelegate.swift에 들어간다 

 

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    self.window.makeSecure()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    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)
   }
 }

 

빨간 부분을 추가하면 캡쳐서 검은화면으로 나온다.

 

 

android

https://pub.dev/packages/flutter_windowmanager/example

라이브러리 설치 후 main에 넣는다

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
  runApp(MyApp());
}

 

캡처시 문구가뜬다.

 

 

참고:
https://stackoverflow.com/questions/52317217/flutter-disable-screenshot-capture-for-app

https://stackoverflow.com/questions/72380810/how-to-prevent-taking-screen-shoot-in-flutter-ios

반응형

+ Recent posts