如何在flutter ios应用程序中阻止截图?

问题描述 投票:0回答:1

我试图在我的 flutter ios 应用程序中阻止屏幕截图,但它不起作用。用户仍然可以在他的设备中截取屏幕截图。您能帮我在我的 iOS 版 Flutter 应用程序中实现阻止屏幕截图吗?预先感谢。

这是我的 AppDelegate.swift 文件代码:

import UIKit
import Flutter

@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)
  }


  // Screenshot Prevent Functions


  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)
    }
  }
ios flutter screenshot appdelegate flag-secure
1个回答
0
投票

你试过这个吗?

import Flutter
import UIKit

let CHANNEL = "disable_screenshots"

class AppDelegate: FlutterAppDelegate {
override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
    let channel = FlutterMethodChannel(name: CHANNEL, binaryMessenger: controller.binaryMessenger)
    
    channel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in
        if (call.method == "disable") {
            UIScreen.main.isCapturedDidChange = { [weak self] in
                if UIScreen.main.isCaptured {
                    UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
                }
            }
            result(true)
        } else {
            result(FlutterMethodNotImplemented)
        }
    }
    
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
© www.soinside.com 2019 - 2024. All rights reserved.