Flutter为BlinkId插件添加了新的ViewController



我正在开发一个flutter应用程序,我必须集成BlinkId插件来扫描文档它没有flutter插件,所以我使用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");          
}
}

您应该删除中间ViewController实例,并在UINavigationViewController之上或直接在topMostViewController之上显示recognizerRunneViewController(负责ID扫描(。

以下是github问题的链接,该问题有助于解决方案:https://github.com/BlinkID/blinkid-ios/issues/294


编辑:2020年6月起的BlinkID。支持Flutter应用程序与官方插件的开箱即用集成。该插件在以下位置可用:https://github.com/blinkid/blinkid-flutter

相关内容

  • 没有找到相关文章

最新更新