BlinkID / blinkid-ios

Everything you need to add AI-driven ID scanning into your native iOS app.
https://microblink.com/products/blinkid
386 stars 89 forks source link

Migration from 2.16.0 to 4.1.0 #194

Closed yaakovgamliel closed 6 years ago

yaakovgamliel commented 6 years ago

We have been using the SDK with very good results for the last one year and a half, currently we're trying to move to the new version (4.1.0) but we haven't been able to scan any code.

Presenting Controller:

//
//  RetailerViewController.swift
//

import UIKit
import MicroBlink

class RetailerViewController: BaseViewController {

    let viewModel = RetailerViewModel()

    var pdf417Recognizer : MBPdf417Recognizer?
    var barcodeRecognizer : MBBarcodeRecognizer?

    private var pullingTimer: Timer?
    private let dropDown: DropDown = dropdownBuilder()

    internal static func instantiate() -> RetailerViewController {
        return Storyboard.retailer.instantiate(RetailerViewController.self)
    }
}

extension RetailerViewController {

    @IBAction func scannButonTouched(_ sender: Any) {
        presentScanner()
    }

    func presentScanner() {
        MBMicroblinkSDK.sharedInstance().setLicenseKey("my license goes here")

        /** Create barcode recognizer */
        self.barcodeRecognizer = MBBarcodeRecognizer()
        self.barcodeRecognizer?.scanQrCode = true

        self.pdf417Recognizer = MBPdf417Recognizer()
        self.pdf417Recognizer?.scanUncertain = true

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

        /** Create your overlay view controller */
        let customOverlayViewController = OverlayViewController.instantiate()

        /** This has to be called for custom controller */
        customOverlayViewController.reconfigureRecognizers(recognizerCollection)

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

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

Overlay Controller

//
//  OverlayViewController.swift

import UIKit
import MicroBlink

class OverlayViewController: MBCustomOverlayViewController {

    let viewModel = OverlayViewModel()

    internal static func instantiate() -> OverlayViewController {
        return Storyboard.scanner.instantiate(OverlayViewController.self)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        super.recognizerRunnerViewControllerDelegate = self as? MBRecognizerRunnerViewControllerDelegate
    }
}

extension OverlayViewController: MBScanningRecognizerRunnerViewControllerDelegate {
    func recognizerRunnerViewController(_ recognizerRunnerViewController: UIViewController & MBRecognizerRunnerViewController,
                                        didFinishScanningWith state: MBRecognizerResultState) {
        print("Got something")
    }
}

Console output:

E] func [line:78] 2018-08-27 12:23:21.207934+0300 pos[1763:437565] ZXing failure
[E] func [line:78] 2018-08-27 12:23:21.954987+0300 pos[1763:437565] ZXing failure
[E] func [line:78] 2018-08-27 12:23:23.127619+0300 pos[1763:437565] ZXing failure
[E] func [line:78] 2018-08-27 12:23:24.293598+0300 pos[1763:437565] ZXing failure
[E] func [line:78] 2018-08-27 12:23:25.143741+0300 pos[1763:437565] ZXing failure
[E] func [line:115] 2018-08-27 12:25:31.183347+0300 pos[1763:437565] Failed to read format information
[E] func [line:115] 2018-08-27 12:25:32.302528+0300 pos[1763:437565] Failed to read format information
[E] func [line:115] 2018-08-27 12:25:33.471502+0300 pos[1763:437565] Failed to read format information
[E] func [line:78] 2018-08-27 12:25:42.645378+0300 pos[1763:437975] ZXing failure
[E] func [line:78] 2018-08-27 12:25:42.723078+0300 pos[1763:437975] ZXing failure
[E] func [line:78] 2018-08-27 12:25:42.895364+0300 pos[1763:437975] ZXing failure

In previous version we didn't have any issue, the console output also includes error info on the intent of scanning a simple barcode from a notebook.

[E] func [line:115] 2018-08-27 12:25:31.183347+0300 pos[1763:437565] Failed to read format information

all the other messages came from trying to scan a California US driving license barcode

juraskrlec commented 6 years ago

Hi @yaakovgamliel

you are conforming to MBRecognizerRunnerViewControllerDelegate in your code and not MBScanningRecognizerRunnerViewControllerDelegate.

Change it to this in your OverlayViewController:

super.scanningRecognizerRunnerViewControllerDelegate = self;

yaakovgamliel commented 6 years ago

Thanks @juraskrlec it's working as expected now