See this part to get SDK download link.
Add local plugin to your project:
x# remove exist plugin if needed. cordova plugin remove aai-ios-liveness-detection-plugin
cordova plugin add /path/to/guardian-liveness-detection-cordova-plugin-iosIf you get error like "CordovaError: Could not determine package name from output", try using a lower version of npm(e.g.
nvm install 14.19.0).
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>
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() { document.getElementById('test-liveness-button').addEventListener('click', showLivenessView)
// Init SDK with license and market(required) var plugin = cordova.plugins.AAIIOSLivenessDetectionPlugin
/* // Configure SDK detection level // Available levels are "EASY", "NORMAL", "HARD". Default is "NORMAL". // Note that this method must be called before "initSDKWithLicenseAndMarket", otherwise it won't take effect. plugin.setDetectionLevel("NORMAL") */
// Your server needs to call openAPI to obtain license content var license = "your-license-content" /* Market available value are as follows: Indonesia India Philippines Vietnam Thailand Mexico Malaysia Pakistan Nigeria Colombia Singapore */ var market = plugin.MARKET.Indonesia plugin.initSDKWithLicenseAndMarket(license, market, function(result){ document.getElementById('sdk-callback-msg').innerHTML = 'initSDKWithLicenseAndMarket:' + result })
// Get SDK version (optional) plugin.getSdkVersion(function(version) { console.log(version) document.getElementById('test-liveness-button').innerHTML = version + '-liveness-sdk-test' })
// Config SDK (optional) /* // You can also specify the motion detection sequence yourself, // as the sequence and number are not fixed. plugin.setDetectionActions([plugin.ACTION.Blink, plugin.ACTION.Mouth])
plugin.setAvatarPreviewWidth(250)
plugin.setAvatarPreviewMarginTop(200)
// If you pass false, the SDK will not display the default loading view, // you need to display and close the custom loading view in 'onLivenessViewBeginRequest' and 'onLivenessViewEndRequest', respectively. plugin.showHUD(true) */
/* // User binding (optional, but strongly recommended). // You can use this method to pass your user unique identifier to us, // we will establish a mapping relationship based on the identifier。 // It is helpful for us to check the log when encountering problems. plugin.setUserId("your-user-id") */
/* // Set whether to detect face occlusion.(optional) // If this value is set to true, SDK will detect face occlusion before entering the action. The default value is false. plugin.setDetectOcclusion(true) */
/* /// Set the timeout for action detection, default is 10s. /// /// Note that this value represents the timeout for an action, /// not the total timeout for all actions. plugin.setActionTimeoutInterval(10) */
/* /// Set the timeout for prepare stage, default is 10s. /// /// This value refers to the time from when the sdk page is displayed to when the motion detection is ready. /// For example, after the sdk page is presented, if the user does not hold the phone upright or put the face in the detection area, /// and continues in this state for a certain period of time, then the `onDetectionFailed` will be called, /// and the value of the "key" is "fail_reason_prepare_timeout". plugin.setPrepareTimeoutInterval(10) */ /* /// Specify which language to use for the SDK. If this value is not set, /// the system language will be used by default. If the system language is not supported, /// English will be used. /// /// The languages currently supported by sdk are as follows: /// /// "en" "id" "vi" "zh-Hans" "th" "es" "ms" "hi" plugin.setLanguage("en") */
/* // Set the color of the round border in the avatar preview area. Default is clear color(#00000000). plugin.setRoundBoderColor("#FF0000") */
/* // Set the color of the ellipse dashed line that appears during the liveness detection. Default is white color. plugin.setEllipseLineColor("#00FF00") */
/* // Whether to allow to play prompt audio. Default is true. plugin.setPlayPromptAudio(true) */
/* // Whether to display animation images. Default is true. If you set false, then animation images will be hidden. plugin.setShowAnimationImgs(true) */
// Config SDK callback configSDKCallback()}
function configSDKCallback() { var plugin = cordova.plugins.AAIIOSLivenessDetectionPlugin
//Set callback /* Required */ plugin.onCameraPermissionDenied(function(key, message) { console.log('onCameraPermissionDenied:', key, message) //close liveness page plugin.closeSDKPage() })
/* Optional */ plugin.onDetectionReady(function(key, message) { console.log('onDetectionReady:', key) })
/* Optional */ plugin.onDetectionTypeChanged(function(key, message) { console.log('onDetectionTypeChanged:', key) })
/* Required */ plugin.onDetectionComplete(function(livenessId, base64ImgStr) { console.log('onDetectionComplete:', livenessId) /* You need to give the livenessId to your server, then your server will call the anti-spoofing api to get the score of this image. The default base64Img size is 300x300. */ //close liveness page plugin.closeSDKPage() })
/* Required */ plugin.onDetectionFailed(function(key, message) { console.log('onDetectionFailed:', key, message) //close liveness page plugin.closeSDKPage() })
/* Optional */ plugin.onLivenessViewBeginRequest(function() { console.log('onLivenessViewBeginRequest') })
/* Required */ plugin.onLivenessViewRequestFailed(function(code, message, transactionId) { console.log('onLivenessViewRequestFailed:', code, message, transactionId) //close liveness page plugin.closeSDKPage() })
/* Optional */ plugin.onLivenessViewEndRequest(function() { console.log('onLivenessViewEndRequest') })}
function showLivenessView() { //Show SDK Page. /* By default, this page is displayed modally. If you need other presentation type, please modify the 'showSDKPage:' method in 'AAIIOSLivenessDetectionPlugin.m' */ cordova.plugins.AAIIOSLivenessDetectionPlugin.showSDKPage()}
setPlayPromptAudio and setShowAnimationImgs.setDetectionLevel, setRoundBoderColor, setEllipseLineColor.setActionTimeoutInterval, setPrepareTimeoutInterval, setLanguage.AAIModel.bundle resource.