Documentation

Integration (Cordova)

Integration Documentation for Cordova Compatible with Liveness Detection V4.x Version.

Overview-Android

  • Minimum Android version:4.4 (API Level:19)
  • Compilation Android SDK version:API Level:35
  • Target Android SDK version:API Level:35
  • Supported CPU architectures:armeabi-v7a,arm64-v8a
  • SDK incremental package size:4.5MB+

    If you have requirements for package size, you can refer to this to reduce the package size by approximately 1.4MB.

  • Capture image size:default capture image resolution 600px*600px, size is about 300KB, support custom image size range: 300px~1000px
  • Supported languages:
    • English
    • Indonesian
    • Vietnamese
    • Chinese
    • Hendi
    • Thai
    • Spanish
  • Use-permissions
    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />

Overview-iOS

SDK requirements and limitations as below:

  • Minimum iOS version: iOS 10.0
  • Additional dependent third-party libraries: None
  • Supported CPU architectures: arm64, x86_64
  • SDK package size: 6.9MB(arm64, disable bitcode)
  • Supported bitcode: NO
  • Supported languages: en, zh-Hans, id, vi, th, es, ms, hi,fil
  • Use-permissions: NSCameraUsageDescription

Compliance Explanation

Click to view the compliance explanation

Release Notes

Click to show release notes

Demo

Install IDV-Demo.apk to your phone and log in with the test account.

Migration Guides

If you are upgrading from an older version of the Liveness SDK, please refer to this document to understand the changes.

Installation

Add the dependency in your React Native project’s package.json file.

  "dependencies": {
    ...
    "liveness-plugin-cordova": "^4.1.1"
  },

For iOS, you need to do:

  1. specify the SDK name and url in the Podfile.
    pod 'AAILivenessUI', :http => 'https://prod-guardian-cv.oss-ap-southeast-5.aliyuncs.com/sdk/iOS-liveness-detection/4.1.1/iOS-Liveness-SDK-V4.1.1.tar.bz2', type: :tbz
    
    pod 'AAILivenessModel', :http => 'https://prod-guardian-cv.oss-ap-southeast-5.aliyuncs.com/sdk/iOS-libraries/AAILivenessModel/4.0.0/AAILivenessModel-V4.0.0.tar.bz2', type: :tbz
    
    pod 'AAICore', :http => 'https://prod-guardian-cv.oss-ap-southeast-5.aliyuncs.com/sdk/iOS-libraries/AAICore/1.0.1/AAICore-V1.0.1.tar.bz2', type: :tbz
    
    pod 'AAINetwork', :http => 'https://prod-guardian-cv.oss-ap-southeast-5.aliyuncs.com/sdk/iOS-libraries/AAINetwork/AAINetwork-V1.0.4.tar.bz2', type: :tbz 
    
    pod 'AAIDataVisorSDK', :http => 'https://prod-guardian-cv.oss-ap-southeast-5.aliyuncs.com/sdk/iOS-AAIDataVisor-SDK/0.1.5/iOS-AAIDataVisorSDK-V0.1.5.tar.bz2', type: :tbz
  2. Run pod install to install the dependencies in your project.
  3. Add camera usage description in Info.plist as bellow. Ignore this step if you have added those.
    <key>NSCameraUsageDescription</key>
    <string>Use the camera to detect the face movements</string>

Usage

  1. Initialization SDK.
    var liveness = cordova.plugins.liveness;
    var market = liveness.Market.Indonesia;
    liveness.initSDKOfMarket(market, function () {}, function (error) {})
  2. Check license

    The license is obtained by your server calling our openAPI, you need to check license before starting the liveness detection activity.

    const license = "xxx";
    liveness.setLicenseAndCheck(license,
        function (result) {
            if ("SUCCESS" === result) {
                var livenessParams = {
    
                };
                liveness.startLivenessDetection(
                    livenessParams,
                    function (livenessResult) {
    									  // display the result
                    },
                    function (error) {
                        console.error("Liveness Detection Failed.", error);
                    }
                );
            }
        },
        function (error) {
            console.error("License Set Failed.", error);
        }
    );
    
    The returned values of checkResult:
    
    APPLICATION_ID_NOT_MATCH: The package name is not within the authorized scope, please check your package name.
    
    LICENSE_EXPIRE: The license has expired, please confirm that the user has calibrated the phone time.
    
    ERROR_LICENSE(1): The license parsing succeeded, but necessary authentication information is missing, this case generally will not occur.
    
    ERROR_LICENSE(2): The license parsing succeeded, but the internal format is incorrect, this case also generally will not occur.
    
    ERROR_LICENSE(3): It is highly likely that an incompatible SDK license is being used, such as using an IQA license for liveness detection.
    
    ERROR_LICENSE(4, 5): Parsing failed, please check if the license has issues like mismatched quotes, line breaks, etc.
    
  3. You can create SDK launch parameters using the method below. Note that the function below is a complete example, including the SDK initialization and license check mentioned above. You can refer to it directly.
    function startWithLicense(license) {
        if (!license) {
            showMessage('license is empty', 'error');
            return;
        }
    
        if (cordova && cordova.plugins && cordova.plugins.liveness) {
            console.log("success");
        } else {
            showMessage("error", 'error');
            return;
        }
        // Assign the plugin to a shorter variable for convenience
        var liveness = cordova.plugins.liveness;
    
        // Use the Market enum for type safety and code completion
        var market = liveness.Market.Indonesia;
       
        // 1. Init SDK
        liveness.initSDKOfMarket(market,
            function () {
                // 2. Check license
                liveness.setLicenseAndCheck(license,
                    function (result) {
                        if ("SUCCESS" === result) {
                            // 3. Configure liveness params then present SDK page
                            const livenessParams = {
                                cameraType: 'FRONT',
                                queryId: 'your_query_id', // Replace with your query ID
                                ticket: 'your_ticket', // Replace with your ticket
                                detectOcclusion: false, // Whether to detect occlusion
                                auditImageConfig: {
                                    enableCollectSwitch: true, // Whether to enable the collection switch
                                    imageWidth: 400, // Image width
                                    imageQuality: 30, // Image quality
                                    relativeSecondsCaptureAfterCameraLaunched: 3.0, // Capture at a relative number of seconds after the camera is launched
                                },
                                livenessType: 'test_more', // Liveness detection type
                                signatureId: '', // Signature ID, if available
                                distantNearTimeout: 50000, // Timeout for distant-near detection in milliseconds
                                silentTimeout: 50000, // Timeout for silent detection in milliseconds
                                actionTimeout: 10000, // Timeout for actions in milliseconds
                                prepareMillSeconds: 0, // Preparation time in milliseconds
                                resultPictureSize: 600, // Result picture size
                                maxRecordVideoSeconds: 600, // Maximum video recording time in seconds
                                userId: '', // User ID
                                maskColor: '#000000', // Mask color
                                ovalColor: '#000000', // Oval color
                                ovalNormalColor: '#000000', // Normal oval color
                            };
                            liveness.startLivenessDetection(
                                livenessParams,
                                function (result) {
                                    console.log("Step 3: Liveness Detection Completed Successfully.", result);
    
                                    // Display the result
                                    var resultContainer = document.getElementById('result-container');
                                    var resultText = document.getElementById('result-text');
    
                                    if (resultContainer && resultText) {
                                        resultText.textContent = JSON.stringify(result, null, 2);
                                        resultContainer.style.display = 'block';
                                    }
                                },
                                function (error) {
                                    showMessage("Failed: " + error, 'error');
                                }
                            );
                        }
                    },
                    function (error) {
                        console.error("License Set Failed.", error);
                    }
                );
            },
            function (error) {
                console.error("SDK Initialization Failed.", error);
            });
    }

Error Code

See Error Code