Skip to main content

Getting started | Cordova Barcode Scanner

Installation

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

Permissions

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 arguments 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, config):

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


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


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

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?