Skip to main content

SDK Initialization | Capacitor Barcode Scanner

License Key

In order to run the Scanbot SDK within your production app, you must purchase and use a valid Scanbot SDK license.

Each license key is valid only for a given app bundle identifier. You will be unable to use any of the SDK features if the license key is corrupted, expired, or invalid in any other way.

App Identifier

Every app has a unique identifier (sometimes also known as "bundle identifier" or "application ID"). Your license will be bound to this identifier. To request a trial license or purchase a production license you have to provide us the bundle identifier of your app.

Change your app's ID in capacitor.config.ts file to your project:

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
appId: 'io.scanbot.example.sdk.barcode.capacitor',
appName: 'Capacitor Scanbot Barcode Scanner SDK Example',
webDir: 'www/browser',
server: {
androidScheme: 'https'
}
};

export default config;

If you are not using TypeScript in your project, you can use a capacitor.config.json file in the same way.

Check the official documentation regarding Capacitor Configuration for more information.

Getting a Trial License

The Scanbot SDK will run without a license for one minute per session! To get a free, "no-strings-attached" 7-day trial license, please submit the Trial License Form on our website.

Please kindly note that a trial license can only be used in a development and staging environment. You are not allowed to publish your app to the App Store, Play Store, or any 3rd party Android App Store with a trial license.

Purchase a Production License

To get pricing information and purchase a production license for the Scanbot SDK please request a quote.

Initialization

Free Developer Support

We provide free "no-strings-attached" developer support for the implementation & testing of the Scanbot SDK. If you encounter technical issues with integrating the Scanbot SDK or need advice on choosing the appropriate framework or features, please visit our Support Page.

The Scanbot Barcode Scanner SDK must be initialized before usage. Make sure to run the initialization only once per app lifetime. This should ideally be done at the earliest point in the application's lifecycle. Typically, the AppComponent file is good practice because it ensures that the Scanbot Barcode Scanner SDK is ready for use as soon as the app starts.

Example code for initialization:

import { ScanbotBarcodeSDK, ScanbotBarcodeSdkConfiguration } from 'capacitor-plugin-scanbot-barcode-scanner-sdk';

const config: ScanbotBarcodeSdkConfiguration = {
licenseKey: this.licenseKey,
loggingEnabled: !environment.production,
// storageBaseDirectory: (await this.storageBaseDirectoryUri).uri, // Custom storage path
fileEncryptionMode: AppComponent.FILE_ENCRYPTION_ENABLED ? 'AES256' : undefined,
fileEncryptionPassword: AppComponent.FILE_ENCRYPTION_ENABLED ? 'SomeSecretPa$$w0rdForFileEncryption' : undefined,
// see further config parameters
};

try {
const result = await ScanbotBarcodeSDK.initializeSdk(config);
console.log(result.data);
} catch (error: any) {
console.error(error);
}

Configuration

export interface ScanbotBarcodeSdkConfiguration {
/** Optional boolean flag to enable logging. See the "Logging" section below. */
loggingEnabled?: boolean;

/** Optional boolean flag that enables Scanbot SDK Core native logging (default is false, Android only). */
enableNativeLogging?: boolean;

/** Your license key for the Scanbot SDK. See the "License Key" section below. */
licenseKey?: string;

/** Optional directory as file URI to override the default storage base directory of the Scanbot SDK. Refer to the section "Storage" for more details. */
storageBaseDirectory?: string;

/** Optional file encryption mode, 'AES128' or 'AES256'. */
fileEncryptionMode?: FileEncryptionMode;

/** Optional file encryption password. Refer to the section "Storage Encryption" for more details. */
fileEncryptionPassword?: string;

/** If set to `true`, Camera X will be used for the RTU-UI components (Android only). Default is `true`. */
useCameraX?: boolean;

/** If set to `true`, GPU Acceleration will be enabled for Barcode Scanner, Document Scanner and Generic Document Recognizer (Android only). Default is `true`. */
allowGpuAcceleration?: boolean;

/** Enables/disables XNNPACK acceleration for TensorFlow ML models, which provides highly optimized implementations of floating-point neural network operators (Android only) */
allowXnnpackAcceleration?: boolean;
}

Logging

When initializing the Scanbot Barcode Scanner SDK you can enable logging of the SDK. By default logging is disabled.

const config: ScanbotBarcodeSdkConfiguration = {
licenseKey: this.licenseKey,
loggingEnabled: true,
enableNativeLogging: true,
};

try {
const result = await ScanbotBarcodeSDK.initializeSdk(config);
console.log(result.data);
} catch (error: any) {
console.error(error);
}

On Android logs are printed into LogCat. The easiest way to check the log outputs on Android is to use the Android Debug Bridge (adb) (e.g. $ adb -s <DEVICE_ID> shell "logcat").

On iOS all logs are printed to the console. Please use Xcode to check the log outputs.

Please note: While it may be useful for development, consider switching logging OFF in production builds for security and performance reasons!

Best way is to use the environment.production variable.

const config: ScanbotBarcodeSdkConfiguration = {
licenseKey: this.licenseKey,
loggingEnabled: !environment.production,
enableNativeLogging: !environment.production,
};

try {
const result = await ScanbotBarcodeSDK.initializeSdk(config);
console.log(result.data);
} catch (error: any) {
console.error(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?