1

我正在开发一个颤振应用程序,并且我已经集成了 BlinkId 插件来扫描没有颤振插件的文档,所以我使用 MethodChannel 在本机代码上调用一个方法,然后我尝试添加插件的本机代码。

一切正常,插件的视图正在打开并且扫描已成功完成,但即使我单击关闭,扫描视图也不会关闭,假设取消扫描。

除 viewdidload 外,其他方法似乎都不起作用,但 didfinishscanning 或 didtabclose 不起作用。

这是我的代码:

import UIKit
import Flutter
import GoogleMaps
import Microblink
var _result: FlutterResult?

@UIApplicationMain
 @objc class AppDelegate: FlutterAppDelegate {

override func application(
 _ application: UIApplication,
 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
 ) -> Bool {
  let controller : FlutterViewController = window?.rootViewController as! FlutterViewController



  let scanIdChannel = FlutterMethodChannel(name: "native.wasfago.scanId",
                                            binaryMessenger: controller.binaryMessenger)
  scanIdChannel.setMethodCallHandler({
  (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
    // Note: this method is invoked on the UI thread.
    guard call.method == "scanId" else {
      result(FlutterMethodNotImplemented)
      return
    }
    _result = result
    self.scanId(result: result) // handle click event from flutter button
    print("clicked!")

  })
  GeneratedPluginRegistrant.register(with: self)
  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
 }
 private func scanId(result: FlutterResult) {

    let viewCtrl = ViewController()
    topMostController().view.addSubview(viewCtrl.view)

 }
 func topMostController() -> UIViewController {
       var topController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController
       while ((topController?.presentedViewController) != nil) {
           topController = topController?.presentedViewController

       }
       return topController!
   }
}

class ViewController: UIViewController ,MBBlinkIdOverlayViewControllerDelegate{
   func blinkIdOverlayViewControllerDidTapClose(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController) {
    print("Closed!!!!!!!!!")
   }


   var blinkIdRecognizer : MBBlinkIdCombinedRecognizer?

   override func viewDidLoad() {
      super.viewDidLoad()
      // Valid until: 2020-06-26

      self.didTapScan()
      print("View Loaded!")
   }

   @IBAction func didTapScan() {
MBMicroblinkSDK.sharedInstance().setLicenseKey("sRwAAAEPY29tLnczNC53YXNmYWdvfIRuYWSSC81qt+lUDRzpTwtWuUsIPrIHmH2dNCTjx5qYKCfr3nKw9UVE7TIRv2nq/jDlTtqhcVZA+4dyVG8moP4DeOygPcRAkdy6L+WpNhacuZMjrTAUmGwooe3CSzaj8D8Y6Znf98SHVIE9bxdSv23SOfCQnNsoCSksIYvpjVjpT5DUExr6qSY+QqeH3EUxDR9GqIPgeiEGIXZUeOdqnIyNiGH8PYpfF9Uv79HEacBncbHDMwfzZTSXc2VYttRgae1QAA9h5hAtUc8VhH1g")
    /** Create BlinkID recognizer */
    self.blinkIdRecognizer = MBBlinkIdCombinedRecognizer()
    self.blinkIdRecognizer?.returnFullDocumentImage = true;

    /** Create settings */
    let settings : MBBlinkIdOverlaySettings = MBBlinkIdOverlaySettings()

    /** Crate recognizer collection */
    let recognizerList = [self.blinkIdRecognizer!]
    let recognizerCollection : MBRecognizerCollection = MBRecognizerCollection(recognizers: recognizerList)

    /** Create your overlay view controller */
    let blinkIdOverlayViewController : MBBlinkIdOverlayViewController = MBBlinkIdOverlayViewController(settings: settings, recognizerCollection: recognizerCollection, delegate: self)

    /** Create recognizer view controller with wanted overlay view controller */
    let recognizerRunneViewController : UIViewController = MBViewControllerFactory.recognizerRunnerViewController(withOverlayViewController: blinkIdOverlayViewController)
    recognizerRunneViewController.modalPresentationStyle = .fullScreen

    /** Present the recognizer runner view controller. You can use other presentation methods as well (instead of presentViewController) */
    self.topMostController().present(recognizerRunneViewController, animated: true, completion: nil)

//    let navigationController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController
 //   navigationController?.pushViewController(recognizerRunneViewController, animated: true)


}

    func topMostController() -> UIViewController {
      var topController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController
      while ((topController?.presentedViewController) != nil) {
        topController = topController?.presentedViewController
      }
      return topController!
    }
    func blinkIdOverlayViewControllerDidFinishScanning(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController, state: MBRecognizerResultState) {
        /** This is done on background thread */
        print("success scaning");          

    }

}
4

1 回答 1

3

您应该删除中间ViewController实例,并将recognizerRunneViewController(负责 ID 扫描的)显示UINavigationViewControllertopMostViewController.

这是帮助解决方案的 github 问题的链接:https ://github.com/BlinkID/blinkid-ios/issues/294


编辑:从 2020 年 6 月开始的 BlinkID。支持在 Flutter 应用程序中使用官方插件进行开箱即用的集成。该插件可在此处获得:https ://github.com/blinkid/blinkid-flutter

于 2020-04-02T17:36:23.050 回答