Installation Guide for barKoder's Nativescript Barcode Reader SDK
1. Environment Setup for NativeScript #
Before you begin building NativeScript apps, make sure your development environment is properly configured.
2. Add our barkoder-nativescript package #
You can integrate the barkoder-nativescript package into your project in two ways:
Option A – Install from npm #
If your project uses npm, run:
npm i barkoder-nativescript
Option B – Install from a Local Package #
- Download the package from the barKoder Developer Portal.
- Unzip the archive.
- Add the package to your project by specifying its local path:
tns plugin add <path to barkoder-nativescript package>
3. Import package #
Import the Barkoder Constants in your project with:
import { BarkoderConstants } from 'barkoder-nativescript/barkoder-nativescript.common';
4. BarkoderView #
At this point the barkoder-nativescript package is installed and imported in your project. Next step is to add the BarkoderView in your layout.
<Page >
...
<Barkoder:BarkoderView id="barkoderView" class="scanner-container" width="100%" height="70%"/>
...
5. Init BarkoderView in ViewModel and set the License Key #
Inside View-Model we need to init a BarkoderView from layout xml.
export class HelloWorldModel extends Observable implements BarkoderConstants.BarkoderResultCallback {
private barkoderView : any
constructor(args) {
super()
this.barkoderView = args.object.page.getViewById('barkoderView');
this.barkoderView.setLicenseKey("License_Key")
}
scanningFinished(results: any[], thumbnails: any[], resultImage: any): void {
console.log(`${results[0].textualData}`)
console.log(`${results[0].barcodeTypeName}`)
}
6. Ready to Scan Event #
SDK is fully initialized and ready for configuration or to start the scanning process.
this.barkoderView.startScanning(this)
For the complete usage of the barkoder-nativescript package please check our sample.
7. Camera permissions #
Our SDK requires camera permission to be granted in order to use scanning features.On Android, you specify the permissions in App_Resources/Android/src/main/AndroidManifest.xml. However, this plugin specifies the required permissions for you. @nativescript/camera. For iOS you need to specify camera permission in Info.plist file inside your project
<key>NSCameraUsageDescription</key>
<string>Camera permission</string>