Getting Started with Infinity Plugins
This guide walks you through installing the Anyline Infinity Plugin, initializing the SDK, and running your first scan.
Prerequisites
-
A valid Anyline license key. Obtain one by following the License Key Generation guide.
Every license is bound to a Bundle Identifier. If you change your Bundle Identifier, you will require a new license. This also ensures that your license key cannot be used in any other application. -
Platform-specific requirements:
-
React Native: React Native 0.72+, Node.js 18+
-
Step 1: Install the Plugin
-
React Native
Install the Anyline plugin via npm or yarn:
npm install anyline-ocr-react-native-module
# or
yarn add anyline-ocr-react-native-module
On Android, add the Anyline Maven repository to your project. For Expo projects, add it to app.json:
{
"expo": {
"plugins": [
["expo-build-properties", {
"android": {
"extraMavenRepos": [
"https://mobile-sdk-android.anyline.io/release/"
]
}
}]
]
}
}
For bare React Native projects, add the repository to your project-level build.gradle or settings.gradle:
allprojects {
repositories {
maven { url 'https://mobile-sdk-android.anyline.io/release/' }
}
}
Step 2: Import the Plugin
-
React Native
import { AnylineInfinityPlugin } from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';
const infinityPlugin = new AnylineInfinityPlugin();
Step 3: Initialize the SDK
Initialize the Anyline SDK with your license key. This must be called before starting any scan.
-
React Native
const request = {
licenseKey: 'YOUR_LICENSE_KEY', // Replace with your Anyline License Key
// Optional: only needed if your app bundles custom ML model files provided by Anyline.
// The value depends on where these files are placed in your project. See the Developer Examples.
assetPathPrefix: 'anyline_assets',
};
const response = await infinityPlugin.requestSdkInitialization(request);
if (response.initialized) {
console.log('SDK initialized:', response.succeedInfo);
} else {
console.error('SDK init failed:', response.failInfo?.lastError);
}
Step 4: Prepare a ScanViewConfig
Create a ScanViewConfig JSON to define what and how to scan. See Constructing your Configuration JSON using JSON Schemas for details on building your configuration, and ScanViewConfig Documentation for the full schema reference.
{
"viewPluginConfig": {
"pluginConfig": {
"id": "barcode",
"barcodeConfig": {
"barcodeFormats": ["ALL"]
},
"cancelOnResult": true (1)
}
}
}
| 1 | cancelOnResult stops scanning after the first result. Set to false for continuous scanning. |
Save this JSON as a file in your app’s assets and load it as a string at runtime. The resulting string is the scanViewConfigJson used in Step 5.
|
Step 5: Start Scanning and Handle Results
Set up a result subscription, configure the scan request, and start the scan session. The scan session remains active until explicitly stopped or until the user dismisses the scan view. Results arrive as events during the session — you can receive zero or more results before the session ends.
-
React Native
import {
AnylineInfinityPlugin,
ExportedScanResultImageFormat,
} from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';
// 1. Subscribe to scan results before starting the scan
const subscription = infinityPlugin.onScanResults((result) => {
for (const scanResult of result.exportedScanResults ?? []) {
const pluginResult = scanResult.pluginResult;
console.log('Plugin result:', pluginResult);
}
});
// 2. Configure how scan results are delivered
const scanResultConfig = {
imageContainer: {
encoded: {},
},
imageParameters: {
format: ExportedScanResultImageFormat.Png,
quality: 50,
},
};
// 3. Build the scan request
// scanViewConfigJson is a JSON string containing your ScanViewConfig
const request = {
scanViewConfigContentString: scanViewConfigJson,
scanResultConfig: scanResultConfig,
};
// 4. Start scanning — resolves when the scan session ends
const response = await infinityPlugin.requestScanStart(request);
console.log('Scan session ended:', response.status);
// 5. Clean up subscription when done
subscription.remove();
Subscribe to onScanResults before calling requestScanStart. The result stream does not buffer events — any results arriving before the subscription is active are lost.
|
See Scan Result Handling for details on result structure and image handling.
Step 6: Stop Scanning
The scan session ends naturally after the first result when cancelOnResult is set to true in the ScanViewConfig, or after all sub-plugin results are collected when using composite scanning. You only need to call requestScanStop for continuous scanning (cancelOnResult: false) or when you want to stop the session before any result is received.
|
Stop the active scan session programmatically:
-
React Native
// Stop with default behavior
infinityPlugin.requestScanStop();
// Or stop with an optional reason (surfaces in abortInfo.message on the scan response)
infinityPlugin.requestScanStop({ message: 'Scan stopped: no result within timeout' });
Next Steps
-
Infinity Plugin API Reference (full method and event reference)
-
Scan Result Handling (working with scan results and images)
-
Advanced Topics (scan switching, UCR, and platform-specific tips)