Need help with the integration?

Type a word or a phrase to start browsing through articles.

[BlinkID+BlinkCard] Integration instructions for combining 2 SDKs in the same application

Follow

With the release of BlinkCard 2.0, BlinkCard SDK is fully compatible with other Microblink SDKs, which means that you can use it with other Microblink SDKs in the same application.

The example below demonstrates how to combine BlinkCard SDK with BlinkID SDK on native Android and iOS platforms.


Android

Follow the instructions provided for individual SDK integration - BlinkID and BlinkCard but pay attention to which packages you're using. For example, when setting the license key, here's how to choose the MicroblinkSDK from the BlinkCard package:

Screenshot_2021-06-25_at_15.15.08.png

//BlinkID license file
MicroblinkSDK.setLicenseFile("path/to/license/file/within/assets/dir", this);

//BlinkCard license file
com.microblink.blinkcard.MicroblinkSDK.setLicenseFile("path/to/license/file/within/assets/dir", this);

Initialize your recognizers and Recognizer bundle like this:

public class MainActivity extends AppCompatActivity {

private BlinkIdCombinedRecognizer blinkIdCombinedRecognizer;
private RecognizerBundle idRecognizerBundle;

private BlinkCardRecognizer blinkCardRecognizer;
private com.microblink.blinkcard.entities.recognizers.RecognizerBundle cardRecognizerBundle;

public static final int BLINKID_REQUEST_CODE = 0x101;
public static final int BLINKCARD_REQUEST_CODE = 0x102;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

blinkIdCombinedRecognizer = new BlinkIdCombinedRecognizer();
idRecognizerBundle = new RecognizerBundle(blinkIdCombinedRecognizer);

blinkCardRecognizer = new BlinkCardRecognizer();
cardRecognizerBundle = new com.microblink.blinkcard.entities.recognizers.RecognizerBundle(blinkCardRecognizer);

}

Create two separate scanning activities inside the MainActivity:

public void startScanningId() {
BlinkIdUISettings settings = new BlinkIdUISettings(idRecognizerBundle);

ActivityRunner.startActivityForResult(this, BLINKID_REQUEST_CODE, settings);
}

public void startScanningCard() {
BlinkCardUISettings cardUISettings = new BlinkCardUISettings(cardRecognizerBundle);

com.microblink.blinkcard.uisettings.ActivityRunner.startActivityForResult(this, BLINKCARD_REQUEST_CODE, cardUISettings);
}

Fetch your results in onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == BLINKID_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK && data != null) {
// load the data into all recognizers bundled within your RecognizerBundle
idRecognizerBundle.loadFromIntent(data);

// now every recognizer object that was bundled within RecognizerBundle
// has been updated with results obtained during scanning session

// you can get the result by invoking getResult on recognizer
BlinkIdCombinedRecognizer.Result result = blinkIdCombinedRecognizer.getResult();
if (result.getResultState() == Recognizer.Result.State.Valid) {

// result is valid, you can use it however you wish

}
}
} else if (requestCode == BLINKCARD_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK && data != null) {
// load the data into all recognizers bundled within your RecognizerBundle
cardRecognizerBundle.loadFromIntent(data);

// now every recognizer object that was bundled within RecognizerBundle
// has been updated with results obtained during scanning session

// you can get the result by invoking getResult on recognizer
BlinkCardRecognizer.Result result = blinkCardRecognizer.getResult();
if (result.getResultState() == com.microblink.blinkcard.entities.recognizers.Recognizer.Result.State.Valid) {

// result is valid, you can use it however you wish

}
}
}
}

 

iOS

Initial integrations steps

CocoaPods

brew install git-lfs
git lfs install
In the generated Podfile, add the following lines:
pod 'MBBlinkCard', '~> 2.3.0' #or current latest version
pod 'PPBlinkID', '~> 5.12.0' #or current latest version

After that, run the command pod install in the Terminal.

Swift Package Manager (SPM)

  • Go to PROJECT > Swift Packages
  • Click on the "+" sign and enter the following links:

BlinkID:

https://github.com/BlinkID/blinkid-swift-package

BlinkCard:

https://github.com/blinkcard/blinkcard-swift-package

A more detailed view of the integration steps can be found here:

License key setup:

    override func viewDidLoad() {
        super.viewDidLoad()

        //BlinkID license key method
        MBMicroblinkSDK.shared().setLicenseResource("blinkid-license", withExtension: "key", inSubdirectory: "", for: .main) { _ in
        }

        //BlinkCard license key method
        MBCMicroblinkSDK.shared().setLicenseResource("blinkcard-license", withExtension: "key", inSubdirectory: "", for: .main) { _ in
        }
    }


Setting up BlinkID and BlinkCard recognizers and overlays:

BlinkID:

/** Create BlinkID recognizer */
self.blinkidRecognizer = MBBlinkIdRecognizer()
self.blinkidRecognizer?.returnFullDocumentImage = true

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

/** Create 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 */
guard let recognizerRunneViewController: UIViewController =
        MBViewControllerFactory.recognizerRunnerViewController(withOverlayViewController: blinkIdOverlayViewController) else {
                return
        }
      recognizerRunneViewController.modalPresentationStyle = .fullScreen

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


BlinkCard

/** Create BlinkCard recognizer */
self
.blinkCardRecognizer = MBCBlinkCardRecognizer()
self.blinkCardRecognizer?.returnFullDocumentImage = true

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

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

/**
Create your overlay view controller *    

let blinkCardOverlayViewController : MBCBlinkCardOverlayViewController =
MBCBlinkCardOverlayViewController(settings: settings, recognizerCollection: recognizerCollection, delegate: self)       

/**
Create recognizer view controller with wanted overlay view controller */

guard
let recognizerRunnerViewController : UIViewController =
MBCViewControllerFactory.recognizerRunnerViewController(withOverlayViewController: blinkCardOverlayViewController) else {
            return
        }       
recognizerRunnerViewController.modalPresentationStyle = .fullScreen

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

Handling the results

BlinkID:

//MARK: BlinkID Delegate methods
extension
ViewController: MBBlinkIdOverlayViewControllerDelegate {

//Actions when the scanning process is finished
func blinkIdOverlayViewControllerDidFinishScanning(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController, state: MBRecognizerResultState) {

    /** This is done on background thread */
blinkIdOverlayViewController.recognizerRunnerViewController?.pauseScanning()
//Checking the recognizer extracted all of the information
  if self.blinkidRecognizer?.result.resultState == MBRecognizerResultState.valid {
//Getting the document image
      let fullDocumentImage: UIImage! = self.blinkidRecognizer?.result.fullDocumentImage?.image
            print("Got BlinkID image with width: \(fullDocumentImage.size.width), height: \(fullDocumentImage.size.height)")

         /** Needs to be called on main thread beacuse everything prior is on background thread */
            DispatchQueue.main.async {
//Actions with information obtained
              print(self.blinkidRecognizer?.result.description)
print(self.blinkidRecognizer?.result.firstName)           
}
        }
    }

//Actions when the "X" button on the overlay is tapped
func blinkIdOverlayViewControllerDidTapClose(_ blinkIdOverlayViewController: MBBlinkIdOverlayViewController) {
self.dismiss(animated: true, completion: nil)
}
}

 

BlinkCard:

//MARK: BlinkCard Delegate methods

extension ViewController: MBCBlinkCardOverlayViewControllerDelegate {

//Actions when the scanning process is finished
func blinkCardOverlayViewControllerDidFinishScanning(_ blinkCardOverlayViewController: MBCBlinkCardOverlayViewController, state: MBCRecognizerResultState) {

        /** This is done on background thread */
    blinkCardOverlayViewController.recognizerRunnerViewController?.pauseScanning()
//Checking the recognizer extracted all of the information
    if blinkCardRecognizer?.result.resultState == .valid {
//Getting the document image
    let fullDocumentImage: UIImage! = blinkCardRecognizer?.result.firstSideFullDocumentImage?.image
            print("Got payment card image with width: \(fullDocumentImage.size.width), height: \(fullDocumentImage.size.height)")
        /** Needs to be called on main thread beacuse everything prior is on background thread */

        DispatchQueue.main.async {
//Actions with information obtained
print(self.blinkCardRecognizer?.result.cardNumber)
        }
    }
}
    
//Actions when the "X" button on the overlay is tapped
    func blinkCardOverlayViewControllerDidTapClose(_ blinkCardOverlayViewController: MBCBlinkCardOverlayViewController) {
        self.dismiss(animated: true, completion: nil)
    }
//Actions how to handle results from the editing screen
    func blinkCardOverlayViewControllerDidFinishEditing(_ blinkCardOverlayViewController: MBCBlinkCardOverlayViewController, editResult: MBCBlinkCardEditResult) {

        blinkCardOverlayViewController.recognizerRunnerViewController?.pauseScanning()
        /** Needs to be called on main thread beacuse everything prior is on background thread */
        DispatchQueue.main.async {
print(editResult.cardNumber)
      }
    }
}

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments