iOS 2D Liveness Detection SDK (v2.1.0) User Guide

Development Preparation

  1. Contact us to register an account.

Overview

AAILivenessSDK contains four modules, the core module AAILivenessSDK.xcframework, the UI module AAILiveness, the resource module Resource, the network module AAINetwork.xcframework. The actual total size of the SDK is about 6.5MB(arm64, disable bitcode).

SDK requirements and limitations as below:

Migration Guides

  1. When migrating from older SDK to 2.0.1, you need to refer the document to reintegrate the SDK.

  2. When migrating from 1.2.9 to 1.3.0, you need to add the system library Accelerate.framework and replace all of the SDK files.

  3. When migrating from 1.2.8 to 1.2.9, you need to replace all of the SDK files("AAILiveness" folder, "AAILivenessSDK.xcframework" folder, "Resource" folder).

  4. When migrating from 1.2.7 (or lower) to 1.2.8 (or higher), you need to add the system library libz.tbd and replace all of the SDK files.

  5. From 1.2.3 or higher, AAILivenessViewController provides some public interfaces and properties, when upgrading to this version, you should use its public interfaces to implement your custom logic.

  6. If your SDK version is lower than 1.2.0, then after migrating to 1.2.0 or higher, you need to do:

    • Change the parameters of the onDetectionComplete method from NSDictionary to AAILivenessResult.
    • Add AAIModel.bundle resource.
    • Call the [AAILivenessSDK configModelBundlePath:] method to configure the path to the AAIModel.bundle file. You can refer to viewDidLoad method of AAILivenessViewController.m for more details.
  7. We recommend you read the change logs to see what has been updated in the new version of the SDK.

Run demo project

  1. The demo project is included in the SDK compressed package. Download the AAILivenessSDK and extract it, then navigate to the directory of AAILivenessSDKObjCDemo or AAILivenessSDKSwiftDemo project and install the dependencies:

  2. Open xcworkspace file in Xcode.

  3. Specify your market:

  4. Specify license content and start SDK, the license content is obtained by your server calling our openapi.

Installation

CocoaPods

  1. Specify the SDK name and url in the podfile:

  2. Install the dependencies in your project:

  3. Add camera、motion usage description in Info.plist as bellow. Ignore this step if you have added those.

    Note that the SDK needs to detect whether the phone is in an upright position, only when the phone is in an upright position will the SDK start detecting face, so you have to add NSMotionUsageDescription in your Info.plist.

  4. Refer to demo project to see how to use the SDK.

Manually

  1. Download the AAILivenessSDK and AAINetwork, then uncompress them and add AAILivenessSDK folder, AAINetwork.xcframework to your project:

  2. Choose "TARGETS -> General" add the following system libraries and frameworks in the Frameworks, Libraries, and Embedded Content section:

    • libz.tbd
    • libc++.tbd
    • AVFoundation.framework
    • CoreMotion.framework
    • SystemConfiguration.framework
    • CoreTelephony.framework
    • Accelerate.framework
    • Metal.framework
    • MetalKit.framework
  3. Choose "TARGETS -> General -> Frameworks,Libraries,and Embedded Content", then set AAILivenessSDK.xcframework and AAINetwork.xcframework's Embed as "Embed & Sign".

  4. Add camera and motion sensor (gyroscope) usage description in Info.plist as bellow. Ignore this step if you have added those.

    Note that the SDK needs to detect whether the phone is in an upright position, only when the phone is in an upright position will the SDK start detecting face, so you have to add NSMotionUsageDescription in your Info.plist.

Usage

  1. Import SDK and initialize with your market:

  2. Configure SDK license and show SDK page:

Error code

The errorCode values of AAILivenessFailedResult are as follows:

errorCoderaw native sdk codeDescription
PREPARE_TIMEOUTfail_reason_prepare_timeoutTimeout during the preparation stage
ACTION_TIMEOUTfail_reason_timeoutTimeout during the motion stage
MUTI_FACEfail_reason_muti_faceMultiple faces detected during the motion stage
FACE_MISSINGfail_reason_facemiss_blink_mouthFace is missing during the motion stage(blink or open mouth)
FACE_MISSINGfail_reason_facemiss_pos_yawFace is missing during the motion stage(pos yaw)
MUCH_ACTIONfail_reason_much_actionMultiple motions detected during the motion stage
USER_GIVE_UPuser_give_upThe user clicked the top left back button during the detection process
NO_RESPONSE Network request failed
UNDEFINED Other undefined errors
...(Other server side error codes)  

Customizable UI

  1. Action Detection Sequence Customization.

    The number of detectionType is 2 in default detectionActions array and the order of motions is random. You can also specify the motion detection sequence yourself, as the sequence and number are not fixed. One example is as below:

  2. UI Cutomization.

    File nameFile descriptionCustomizable description
    AAILivenessViewController.mDetection pageYou can implement custom UI and other logic by inheriting from this class. See the demo project for how to customize the UI.
    AAILivenessResultViewController.mDetection result pageAll UI elements can be customized. If necessary, you can implement the detectionSuccessBlk and detectionFailedBlk of AAILivenessViewController.h to enter your own app page instead of this result page
    AAIHUD.mActivity Indicator ViewAll UI elements can be customized. If necessary, you can implement the beginRequestBlk and endRequestBlk of AAILivenessViewController.h to show your own activity indicator view

    For more information on how to customize the UI, please refer to the question in the FAQ.

  3. Resources File Customization. Currently, this SDK supports English (en), Simplified Chinese (zh-Hans), Indonesian (id), Vietnamese (vi), Thai (th), Mexican (es), Bahasa Melayu (ms) and Hindi (hi). The SDK will use the corresponding resource file according to the current language of the device. If this device language is not in the above languages, the SDK will use English by default. If you want to support only a fixed language, you can set the language property of AAILivenessViewController. The resource files corresponding to these languages are in the following bundles:

    NameDescriptionCustomizable description
    AAILanguageString.bundleMuti-language bundleCan be modified directly
    AAIAudio.bundleAudio bundleUse your audio file to replace it. NOTE: the audio file name cannot be changed
    AAIImgs.bundleImage bundleUse your image file to replace it. NOTE: the image file name cannot be changed
    AAIModel.bundleModel bundleCannot be modified

 

FAQ

  1. If you add an All Exceptions breakpoint, the code could stop at player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];, Line 163 of file AAILivenessUtil.m. during face detection actions. The solution is to find All Exceptions breakpoint and edit the exception type from "All" to "Objective-C", as shown by figure below.

  2. Can I customize the UI? Yes. From 1.2.3 or higher, AAILivenessViewController provides some public interfaces and properties, see demo project for how to customize UI or logic. For 1.2.2 or lower, AAILivenessViewController does not provide an extensible UI, so you need to modify the source code to meet your requirements. In addition, AAILivenessResultViewController is just a display result page. Normally, you can implement the detectionSuccessBlk and detectionFailedBlk of class AAILivenessViewController to jump to your own app page instead of the AAILivenessResultViewController page.

  3. If I have modified the UI part of the code, how do I upgrade to the new version of the SDK? Usually, only AAILivenessSDK.xcframework will be updated when the SDK is updated, the external open source code will not be modified. If the external open source code is modified in the new version of SDK, there will be detailed instructions in the release log, so you need to read the release log carefully to see if the external code has been modified.

  4. Error: Access for this account is denied You need to bind your app bundleId to the accessKey secretKey on our CMS website.(Personal Management -> ApplicationId Management)

Change logs and release history

See iOS liveness SDK release history