Cordova SDK
Build hybrid mobile applications using Apache Cordova and the Aila SDK. The SDK works with both iOS and Android platforms.
Installation
Install the plugin using the Cordova CLI:
cordova plugin add cordova-plugin-aila-sdk
Or using npm:
npm install cordova-plugin-aila-sdk
Quick Start
Import and initialize the SDK in your Cordova app:
// Access the plugin
const AilaSDK = cordova.plugins.AilaCordovaPlugin;
// Get constants for configuration
const constants = cordova.plugins.AilaSDKConstants;
// Initialize SDK
AilaSDK.init({
multiScanMode: constants.multiScanMode.AilaMultiScanModeOn,
duplicateFilter: constants.duplicateFilter.AilaDuplicateFilterOff,
beepMode: constants.beepMode.AilaBeepModeOff,
id1CardDetectionMode: constants.id1CardDetectionMode.AilaID1CardDetectionModeOn
}).then(() => {
console.log('SDK initialized successfully');
// Read license after successful initialization
return AilaSDK.readLicense('your-license-key-here');
}).then(() => {
console.log('License loaded successfully');
}).catch((error) => {
console.error('Initialization failed:', error);
});
tip
Initialize the SDK when your app starts, typically in the deviceready event handler.
Basic Usage
Here's a complete example with scanning functionality:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
const AilaSDK = cordova.plugins.AilaCordovaPlugin;
const constants = cordova.plugins.AilaSDKConstants;
// Initialize SDK
AilaSDK.init({
multiScanMode: constants.multiScanMode.AilaMultiScanModeOn,
duplicateFilter: constants.duplicateFilter.AilaDuplicateFilterOff,
beepMode: constants.beepMode.AilaBeepModeOff
}).then(() => {
return AilaSDK.readLicense('your-license-key-here');
}).then(() => {
console.log('SDK ready to scan');
});
// Listen for scan events
window.addEventListener('rawScanData', (event) => {
console.log('Scan Type:', event.scanType);
console.log('Scanned Data:', event.scanText);
// Process the scanned data
handleScanResult(event.scanText);
// Reset for next scan in multi-scan mode
AilaSDK.resetScan();
});
// Start scanning button
document.getElementById('startBtn').addEventListener('click', () => {
AilaSDK.scanStart().then(() => {
console.log('Scanning started');
});
});
// Stop scanning button
document.getElementById('stopBtn').addEventListener('click', () => {
AilaSDK.scanStop().then(() => {
console.log('Scanning stopped');
});
});
}
function handleScanResult(data) {
// Your business logic here
console.log('Processing scan:', data);
}
MRZ Scanning Example
To enable MRZ (Machine Readable Zone) scanning with detection feedback:
const AilaSDK = cordova.plugins.AilaCordovaPlugin;
const constants = cordova.plugins.AilaSDKConstants;
// Configure for MRZ scanning
AilaSDK.init({
mrzMode: constants.mrzMode.AilaMRZModeOn,
mrzDetectionMode: constants.mrzDetectionMode.AilaMRZDetectionModeOn,
beepMode: constants.beepMode.AilaBeepModeOff
}).then(() => {
return AilaSDK.readLicense('your-license-key-here');
});
// Show MRZ scanning guides
AilaSDK.displayMRZGuides(true);
// Listen for scan events
window.addEventListener('rawScanData', (event) => {
if (event.scanType === 'MRZ') {
console.log('MRZ Data:', event.scanText);
// Parse MRZ JSON data
const mrzData = JSON.parse(event.scanText);
console.log('Passport Number:', mrzData.documentNumber);
console.log('Name:', mrzData.givenNames, mrzData.surname);
}
});
// Start scanning
AilaSDK.scanStart();
ID-1 Card Capture Example
Capture images of ID-1 cards (credit card size) using the ID Tray:
const AilaSDK = cordova.plugins.AilaCordovaPlugin;
const constants = cordova.plugins.AilaSDKConstants;
// Enable ID-1 card detection
AilaSDK.setConfig({
id1CardDetectionMode: constants.id1CardDetectionMode.AilaID1CardDetectionModeOn
});
// Listen for image capture results
window.addEventListener('imageCaptured', (event) => {
if (event.success) {
console.log('Card image captured');
// event.image contains base64-encoded image
displayImage(event.image);
} else {
console.error('Capture failed:', event.error);
}
});
// Trigger card capture
document.getElementById('captureBtn').addEventListener('click', () => {
AilaSDK.captureImage().then(() => {
console.log('Capture initiated');
});
});
function displayImage(base64Image) {
const img = document.createElement('img');
img.src = 'data:image/jpeg;base64,' + base64Image;
document.getElementById('imageContainer').appendChild(img);
}
Next Steps
- Requirements - Platform and permission requirements
- Supported Formats - Barcode types and MRZ support
- Constants - Configuration constants reference
- API Reference - Complete method documentation