Migration from the Legacy Plugin to Infinity Plugin
This guide helps you migrate from the legacy Anyline plugin API to the Infinity Plugin API.
Key Differences
| Aspect | Legacy Plugin | Infinity Plugin |
|---|---|---|
Session model |
One-shot (scan → result → done) |
Persistent (init → scan → results 0..N → stop) |
Configuration |
Passed per scan call |
|
Results |
Single callback per scan |
Event stream (0..N results per session) |
Scan switching |
Not supported (stop + restart) |
Supported mid-session |
Plugin class |
Platform-specific class names |
|
SDK initialization |
Implicit or per-scan |
Explicit |
UCR support |
Available (React Native only) |
Built-in via |
Cached events exporting |
Available via |
Built-in via |
Migration Steps
Step 1: Update Dependencies
Replace the legacy plugin dependency with the latest version that includes the Infinity Plugin.
-
Cordova
Add the Anyline plugin to your Cordova project:
cordova plugin add io-anyline-cordova
On Android, add the Anyline Maven repository. Create or edit platforms/android/app/build-extras.gradle:
repositories {
maven { url 'https://mobile-sdk-android.anyline.io/release/' }
}
Step 2: Update Imports
Replace legacy plugin imports with the Infinity Plugin:
-
Cordova
The plugin is available as a global after installation via the clobbers target:
// Available globally via window.AnylineInfinity
var anylineInfinity = window.AnylineInfinity;
Step 3: Initialize the SDK Explicitly
The Infinity Plugin requires explicit SDK initialization before scanning. This replaces any implicit initialization in the legacy API.
-
Cordova
var 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: 'www/assets/anyline_assets',
};
anylineInfinity.requestSdkInitialization(
request,
function(response) {
if (response.initialized) {
console.log('SDK initialized:', response.succeedInfo);
} else {
console.error('SDK init failed:', response.failInfo.lastError);
}
},
function(error) {
console.error('SDK init error:', error);
}
);
Step 4: Update Scanning Code
Replace legacy scan calls with requestScanStart. The key difference is that results now arrive via an event stream rather than a single callback.
-
Cordova
// Enums are available via window.AnylineEnums (merged by plugin.xml)
var ExportedScanResultImageFormat = AnylineEnums.ExportedScanResultImageFormat;
// Specify image format and delivery method for scan results
var scanResultConfig = {
imageContainer: {
encoded: {},
},
imageParameters: {
format: ExportedScanResultImageFormat.Png,
quality: 50,
},
};
// scanViewConfigJson is a JSON string containing your ScanViewConfig
var request = {
scanViewConfigContentString: scanViewConfigJson,
scanResultConfig: scanResultConfig,
};
anylineInfinity.requestScanStart(
request,
function(response) {
// Called once when the scan session ends
console.log('Scan session ended:', response.status);
},
{
onScanResults: function(result) {
// Called 0..N times during scanning
var scanResult = result.exportedScanResults && result.exportedScanResults[0];
console.log('Scan result:', scanResult && scanResult.pluginResult);
},
}
);
Step 5: Update Result Handling
The onScanResults event stream now delivers results as WrapperSessionScanResultsResponse objects. The result structure is similar to the legacy format but wrapped in the new response envelope.
See Scan Result Handling for details.
Breaking Changes
|
The Legacy Plugin and the Infinity Plugin are delivered in the same package, but they must not be used together in the same application. Both plugins communicate with the native Anyline SDK through a shared internal session. Using both simultaneously causes:
If you are migrating from the Legacy Plugin, complete the migration fully before removing legacy code. Do not call methods from both plugins within the same application lifecycle. |
-
requestSdkInitializationmust be called before any scan operations -
The scan method no longer returns scan results directly. Subscribe to
onScanResultsinstead. -
The scan session lifecycle is explicit: you must call
requestScanStopor wait for session end -
Pass the
ScanViewConfigas a JSON string, not as a native configuration object
Next Steps
-
Getting Started with Infinity Plugins — step-by-step setup with the Infinity Plugin
-
Infinity Plugin API Reference — complete method reference for the Infinity Plugin
-
Scan Result Handling — handling scan results and images