Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags more
Archives
Today
Total
관리 메뉴

혼자서 앱 만드는 개발자 함께하는 AI 세상

플러터 스크린 캡쳐 이벤트 처리 본문

플러터 앱개발

플러터 스크린 캡쳐 이벤트 처리

혼앱사 2023. 12. 19. 13:45
반응형
  • 스크린 캡쳐 이벤트를 받아서 처리 하는 로직  
 

screenshot_callback | Flutter Package

Flutter plugin that allows you to detect mobile screenshot and execute callback functions on iOS and Android.

pub.dev

class GetStartedController extends GetxController {
  Rx<GetStartedModel> getStartedModelObj = GetStartedModel().obs;
  final ScreenCaptureEvent screenListener = ScreenCaptureEvent();

  @override
  void onInit() {
    super.onInit();
    screenListener.addScreenRecordListener((recorded) {
      ///Recorded was your record status (bool)
    });

    screenListener.addScreenShotListener((filePath) {});

    ///You can add multiple listener ^-^
    screenListener.addScreenRecordListener((recorded) {
      print("Hi i'm 2nd Screen Record listener");
    });
    screenListener.addScreenShotListener((filePath) {
      print("Wohooo i'm 2nd Screenshot listener");
    });

 

  • 스크린 캡쳐 방지

 

    SecureShot.on(); 호출 

https://pub.dev/packages/flutter_windowmanager

 

flutter_windowmanager | Flutter Package

A Flutter plugin for manipulating Android WindowManager LayoutParams.

pub.dev

ios 를 channel invoke 를 통해 처리 

  _channel.invokeMethod("unSecureIOS");

 import UIKit
import Flutter
import awesome_notifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  private var textField = UITextField()

  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {

    //함수 추가
    makeSecureYourScreen() 
    
    //MethodChannel생성
    let controller : FlutterViewController = self.window?.rootViewController as! FlutterViewController
    let securityChannel = FlutterMethodChannel(name: "secureShotChannel", binaryMessenger: controller.binaryMessenger)
    securityChannel.setMethodCallHandler({
            (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
            if call.method == "secureIOS" {
                self.textField.isSecureTextEntry = true
            } else if call.method == "unSecureIOS" {
                self.textField.isSecureTextEntry = false
            }
    })
    
      GeneratedPluginRegistrant.register(with: self)
      SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in          
          SwiftAwesomeNotificationsPlugin.register(
            with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)
      }
       return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    private func makeSecureYourScreen() {
        if (!self.window.subviews.contains(textField)) {
            self.window.addSubview(textField)
            textField.centerYAnchor.constraint(equalTo: self.window.centerYAnchor).isActive = true
            textField.centerXAnchor.constraint(equalTo: self.window.centerXAnchor).isActive = true
            self.window.layer.superlayer?.addSublayer(textField.layer)
            textField.layer.sublayers?.first?.addSublayer(self.window.layer)
        }
    }
}
728x90
반응형
Comments