3

我已将 Microblink 读卡器设置为仅读取一侧,并且不允许用户编辑扫描结果:

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

我在这里想念什么?

4

1 回答 1

2

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

关于第二部分(在blinkCardOverlayViewControllerDidFinishScanning方法中), the.combinedResultresult对象的父级,因此您可以使用 theblinkCardRecognizer.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)
              })
          }
      }
于 2021-03-11T10:11:32.260 回答