Skip to main content

Getting started | Cordova Barcode Scanner


The Scanbot Barcode Scanner SDK Cordova Plugin is available as an npm package cordova-plugin-scanbot-barcode-scanner.

You can simply install and add it to your Cordova project with the following command:

$ cordova plugin add cordova-plugin-scanbot-barcode-scanner

Or in an Ionic based project:

$ ionic cordova plugin add cordova-plugin-scanbot-barcode-scanner


During the installation this plugin will try to add all required permissions to your projects automatically. Here is a listing of those permissions to verify:

  • Android (will be added in your AndroidManifest.xml file):

    <uses-permission android:name="android.permission.CAMERA" /> - This permission is used for the camera views.

  • iOS (will be added in your Info.plist file):

    NSCameraUsageDescription - "Privacy - Camera Usage Description". Describe why your app wants to access the camera. By default an empty string value will be added. You can change this value in the config.xml file of your Cordova project - see CAMERA_USAGE_DESCRIPTION.

Promise-based API#

The API as presented in the documentation uses the Cordova-style plugin callback signature, where the success and error callbacks are always passed as the first and second argument to each plugin method.

The ScanbotBarcodeSdk.promisify() method returns an object that has all the functions of ScanbotBarcodeSdk but with a promisified signature, that is, where every method returns a Promise, instead of taking success/error callbacks as parameters. The promise-based API is only available when there is a global Promise function provided either by the runtime or by a polyfill. The arrow-style and async/await syntaxes are available only with transpilation, which is available by default to Ionic projects thanks to webpack and Babel.

An example with initializeSdk(success, error, options):

//------ Cordova-style call with callbacks ----------------ScanbotBarcodeSdk.initializeSdk(function(result) {  // success}, function(err) {  // error}, options);

//---------- Promise-style with arrow functions -----------ScanbotBarcodeSdk.promisify().initializeSdk(options).then(result => {  // success}).catch(err => {  // error});

//---------- async/await style (recommended) --------------try {  const result = await ScanbotSdk.promisify().initializeSdk(options);  // success} catch (err) {  // error}