Microblink:扫描后获取值

Microblink: getting values after scanning

我已经将 Microblink 卡 reader 设置为只读取一侧,并且不给用户编辑扫描结果的能力:

func didTapScan() {
        /** Create BlinkCard recognizer */
        blinkCardRecognizer = MBCBlinkCardRecognizer()
        blinkCardRecognizer?.extractCvv = false
        blinkCardRecognizer?.extractIban = false
        blinkCardRecognizer?.extractExpiryDate = false
        
        /** Create BlinkCard settings */
        let settings : MBCBlinkCardOverlaySettings = MBCBlinkCardOverlaySettings()
        settings.enableEditScreen = false
        
        /** Crate recognizer collection */
        let recognizerList = [blinkCardRecognizer!]
        let recognizerCollection : MBCRecognizerCollection = MBCRecognizerCollection(recognizers: recognizerList)
        
        /** Create your overlay view controller */
        let blinkCardOverlayViewController = MBCBlinkCardOverlayViewController(settings: settings, recognizerCollection: recognizerCollection, delegate: self)
        
        /** Create recognizer view controller with wanted overlay view controller */
        // NOTE that I put a bang on the end of this - not good
        let recognizerRunneViewController : UIViewController = MBCViewControllerFactory.recognizerRunnerViewController(withOverlayViewController: blinkCardOverlayViewController)!
        
        /** Present the recognizer runner view controller. You can use other presentation methods as well (instead of presentViewController) */
        self.present(recognizerRunneViewController, animated: true, completion: nil)
    }

扫描后,我在委托回调中检查有效状态,然后我尝试从 cardRecognizer 中检索值,但除了崩溃我什么也没得到:

func blinkCardOverlayViewControllerDidFinishScanning(_ blinkCardOverlayViewController: MBCBlinkCardOverlayViewController, state: MBCRecognizerResultState) {
        // this is done on background thread
        // check for valid state
        if state == .valid {
            
            CRASHES HERE
            guard let result = blinkCardRecognizer?.combinedResult else {
                return
            }
            // CRASHES HERE
            print (result)
            
            // first, pause scanning until we process all the results
            blinkCardOverlayViewController.recognizerRunnerViewController?.pauseScanning()
            
            DispatchQueue.main.async(execute: {() -> Void in
                print(self.blinkCardRecognizer)
                // self.dismiss(animated: true, completion: nil)
            })
        }
    }

我在这里错过了什么?

关于第一个代码块,您已正确完成所有操作。

关于第二部分(在blinkCardOverlayViewControllerDidFinishScanning 方法中),.combinedResultresult 对象的父对象,因此您可以使用blinkCardRecognizer.result 代替。

此外,识别器的描述方法似乎有问题(blinkCardRecognizer.result),因此您需要指定要提取的信息。

示例代码为:

extension ViewController: MBCBlinkCardOverlayViewControllerDelegate {
    func blinkCardOverlayViewControllerDidFinishScanning(_ blinkCardOverlayViewController: MBCBlinkCardOverlayViewController, state: MBCRecognizerResultState) {
        /** This is done on background thread */
        
        if state == .valid {

            guard let result = blinkCardRecognizer?.result else {
                  return
              }
            blinkCardOverlayViewController.recognizerRunnerViewController?.pauseScanning()

              DispatchQueue.main.async(execute: {() -> Void in
                print(result.cardNumber)
              })
          }
      }