onLivenessViewRequestFailed
have been removed, and the parameter errorCode
(old version called 'key') of onDetectionFailed
has been changed, please refer to the v3.1.3 change logs for details.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-ios
If 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 and motion sensor (gyroscope) 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>
<key>NSMotionUsageDescription</key>
<string>Use the motion sensor to get the phone orientation</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
// 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
BPS
*/
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")
*/
/*
// Set the color of the color of the ellipse border in 3D mode(near/distant mode). Default is 0x5BC413.
plugin.setEllipseBorderCol3D("#00FF00")
*/
/*
// The normal color of the ellipse border in 3D mode(near/distant mode). Default is #F5F5F5.
// @since 3.3.0
plugin.setNormalEllipseBorderCol3D("#0000FF")
*/
/*
// Set the color of the inner ellipse animation line of the 3D mode(near/distant mode). Default is #5BC413.
plugin.setInnerEllipseLineCol3D("#FF0000")
*/
/*
// Set the color of `AAILoadingHud`. Default is #5BC413.
// @since 3.4.0
plugin.setHudBrandColor("#FF0000")
*/
/*
// 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)
*/
/*
// Optional
// If you enable this feature, the SDK will automatically upload the audit image sequence list to the server after liveness detection complete.
// You can obtained the 'auditImageUrl' fileld in the liveness-detection openapi response. See liveness-detection openapi for more detail.
//
// The first parameter:Whether to collect audit images. Default is false.
// The second parameter:Minimum interval time for capturing images,default interval is 400ms
// The third parameter:Maximum number of captured images,default number is 10
// The fourth parameter:The image width,default width is 400px
// The fifth parameter:The image compress quality,must in [30,100],the default value is 30
plugin.setAuditImageConfig(false,300,2,400,50)
*/
/*
/// Optional
// If you enable this feature, SDK will record video during the detection process.
// After the completion of the liveness process, you can retrieve the 'videoFilePath' by parse the 'additionalInfo'
// in 'onDetectionComplete' callback.
// The video file format is .mp4. Please note that this video can only be obtained through the SDK and
// cannot be obtained from the aai backend. After using the video, it is up to you to decide whether to delete the local file.
//
// The first parameter:Whether to record video. Default value is false.
// The second parameter:The maximum recording duration, in seconds, valid range [2,60], default is 60 seconds.
plugin.setVideoRecorderConfig(true,60)
*/
/*
/// Optional
// Whether to mark the action of tapping back button as "USER_GIVE_UP". The default is false. If you pass true, the `onDetectionFailed`
// will be called when the user taps the top left back button while liveneness detection is running.
plugin.recordUserGiveUp(false)
*/
// 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, additionalInfo) {
//close liveness page
plugin.closeSDKPage()
console.log('onDetectionComplete:', livenessId)
console.log('additionalInfo:', additionalInfo)
/*
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.
The parameter 'additionalInfo' contains the following keys:
- 'eventId': This used to help debug the specific cause of the error.
- 'transactionId': This is used to help debug the specific cause of the server side error.
- 'videoFilePath': The video file path, if you enable the video recording feature, otherwise this key will not exist.
*/
})
/* Required */
plugin.onDetectionFailed(function(errorCode, message, additionalInfo) {
//close liveness page
plugin.closeSDKPage()
console.log('onDetectionFailed:', errorCode, message)
console.log('additionalInfo:', additionalInfo)
})
/* Optional */
plugin.onLivenessViewBeginRequest(function() {
console.log('onLivenessViewBeginRequest')
})
/* 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()
}
The errorCode
values of onDetectionFailed
are as follows:
errorCode | raw native sdk code | Description |
---|---|---|
PREPARE_TIMEOUT | fail_reason_prepare_timeout | Timeout during the preparation stage |
ACTION_TIMEOUT | fail_reason_timeout | Timeout during the motion stage |
MUTI_FACE | fail_reason_muti_face | Multiple faces detected during the motion stage |
FACE_MISSING | fail_reason_facemiss_blink_mouth | Face is missing during the motion stage(blink or open mouth) |
FACE_MISSING | fail_reason_facemiss_pos_yaw | Face is missing during the motion stage(pos yaw) |
MUCH_ACTION | fail_reason_much_action | Multiple motions detected during the motion stage |
USER_GIVE_UP | user_give_up | The user clicked the top left back button during the detection process |
NO_RESPONSE | Network request failed | |
DEVICE_NOT_SUPPORT | device_not_support | The front camera of this device cannot be opened |
UNDEFINED | Other undefined errors | |
...(Other server side error codes) |
setHudBrandColor
method, which is used to set the color of AAILoadingHud
. The default is #5BC413.Added setNormalEllipseBorderCol3D
method, which is used to set the normal color of the ellipse border in 3D mode(near/distant mode). The default is 0xF5F5F5.
If you want to maintain the previous interaction effect, you can call the following codes:
// Other configurations
plugin.setEllipseBorderCol3D("#5BC413")
plugin.setNormalEllipseBorderCol3D("#5BC413")
onLivenessViewRequestFailed
, please use onDetectionFailed
to handle the user's give up action and network request failed.errorCode
of onDetectionFailed
has been changed, please refer to the Error code for details.Added additionalInfo
parameter to onDetectionFailed
method, which contains the following keys:
Added additionalInfo
parameter to onDetectionComplete
method, which contains the following keys:
Added recordUserGiveUp
method, which is used to mark the action of tapping back button as "USER_GIVE_UP". The default is false. If you pass true, the onDetectionFailed
will be called when the user taps the top left back button while liveneness detection is running.
Added method setAuditImageConfig
and setVideoRecorderConfig
to support collecting audit images and recording video during the detection process.
BPS
.setEllipseBorderCol3D
and setInnerEllipseLineCol3D
.setPlayPromptAudio
and setShowAnimationImgs
.setDetectionLevel
, setRoundBoderColor
, setEllipseLineColor
.setActionTimeoutInterval
, setPrepareTimeoutInterval
, setLanguage
.AAIModel.bundle
resource.