Quick Integration Guide

Note

The license file (DFLicense) is used to control the bundle ID and effective time of the APP (the time range can be directly viewed by the file content). Please confirm that the bundle ID of the APP is consistent with the bundle ID of the license. Make sure that the system time of the APP running device is within the valid time of the license.

SDK Directory Structure

image

Integrate the SDK into the development environment

Before you use the SDK, you need to integrate it into your development environment first.

Configuration development environment

1. Import SDK package

Copy the libDFActionLiveness folder (including libDFActionLivenessDetector.a, DFLicense, df_liveness_resource.bundle, .h, .m, etc.) to the project project directory, drag and drop it into the project opened by xcode, check copy, click Finish button.

Note: This SDK does not support the import of CocoaPods.

image

2. Compile option settings
2.1 Need to add Xcode linker parameters: -ObjC and -lstdc++
  • After adding the -ObjC parameter, the linker can load all Objective-C classes and classes in the static library into the final executable.
  • Adding the -lstdc++ parameter is due to the need for c++ standard library support in our static libraries.

Step: TARGETS -> Build Settings -> Linking -> Other Linker Flags: add -lstdc++ and -ObjC.

image

2.2 Need to manually close Bitcode

Step: TARGETS -> BuildSettings -> Enable Bitcode: Set NO.

image

Step: TARGETS ->Build Phases: Add related reference library image

4. When debugging iOS9 or above on Xcode, when calling the camera function, add privacy permission under the info.plist file.
 <key>NSCameraUsageDescription</key>
 <string>cameraDesciption</string>
 <key> NSPhotoLibraryUsageDescription </key>
 <string>cameraDesciption</string>

Start Detection

DFActionfaceViewController Call Flow

DFActionfaceViewController is an example of the action liveness detection SDK we provide. You can set action sequences, threshold, etc. Once setup is complete, you can start detecting.

The details are as follows:

  1. Compliance with the protocol: DFActionLivenessDetectorDelegate

     @interface ViewController () <DFActionLivenessDetectorDelegate>
    
  2. Get resource path

     NSString *strResourcesBundlePath = [[NSBundle mainBundle] pathForResource:@"df_liveness_resource" ofType:@"bundle"];
    
  3. Get the authorization file path

     NSString *licensePath = [[NSBundle mainBundle] pathForResource:@"DFLicense" ofType:@""];
    
  4. Initialize the action liveness detection view controller

     DFActionfaceViewController *livenessVC = [[DFActionfaceViewController alloc] initWithDuration:10.0f resourcesBundlePath:strResourcesBundlePath licensePath:licensePath];
    
  5. Parameter settings You need to set the action sequence and the action thresholds yourself. The SDK will perform action detection based on your settings. You must put the silent action HOLDSTILL first and only have one silent action, the following actions can be combined at will.

     //Can be freely combined according to actual needs, the first action must be silent action and there can only be one silent action in the sequence
     NSArray *arrLivenessSequence = @[@(LIVE_HOLD_STILL), @(LIVE_BLINK) , @(LIVE_MOUTH) , @(LIVE_NOD) , @(LIVE_YAW)];
     NSArray *arrThreshold = @[@(0.7) , @(0.7) , @(0.7) , @(0.7) , @(0.7)];
    
     // Set delegate, callback thread queue, action sequence, and action threshold
     [livefaceVC setDelegate:self callBackQueue:dispatch_get_main_queue() detectionSequence:arrLivenessSequence detectionThreshold:arrThreshold];
    
     // Set the action detection output type
     [livenessVC setOutputType:LIVE_OUTPUT_MULTI_IMAGE];
    
  6. Present action detection view controller

     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:livenessVC];
     [navigationController setNavigationBarHidden:YES];
     [self presentViewController:navigationController animated:YES completion:nil];
    
  7. Implementation methods: DFActionLivenessDetectorDelegate

     - (void)livenessDidStartDetectionWithDetectionType:(LivefaceDetectionType)iDetectionType
                                         detectionIndex:(int)iDetectionIndex;
     {
         // Action detection has started the callback
     }
    
     - (void)livenessTimeDidPast:(double)dPast durationPerModel:(double)dDurationPerModel
     {
         // After the detection starts, if the Duration is greater than 0 when the detector is initialized, this method will be called back every frame (0 in the sample program), and dPast is time-consuming for the current action.
     }
    
     // Action detecting successfully callback
     // data: Pass back the encrypted binary data
     // arrDFImage: Return the DFImage array according to the specified output scheme. See DFImage.h for the DFImage property
     // dfVideoData: Return NSData video data according to the specified output scheme(nil)
     - (void)livenessDidSuccessfulGetData:(NSData *)data
                                 dfImages:(NSArray *)arrDFImage
                              dfVideoData:(NSData *)dfVideoData
     {   
     }
    
     // Action detecting failed callback
     - (void)livenessDidFailWithErrorType:(LivefaceErrorType)iErrorType
                            detectionType:(LivefaceDetectionType)iDetectionType
                           detectionIndex:(int)iDetectionIndex
                                     data:(NSData *)data
                                 dfImages:(NSArray *)arrDFImage
                              dfVideoData:(NSData *)dfVideoData
     {
     }
    
     // Action detecting canceled callback
     - (void)livenessDidCancelWithDetectionType:(LivefaceDetectionType)iDetectionType detectionIndex:(int)iDetectionIndex
     {
     }
    

DFActionLivenessController Call Flow

DFActionLivenessController is written on DFActionfaceViewController that has some default logic. If you don't have customization requirements, you can use DFActionLivenessController directly.

  1. Compliance with the protocol: DFActionLivenessDetectorDelegate

     @interface ViewController () <DFActionLivenessDelegate>
    
  2. Initialization parameter setting

    DFActionLivenessController is init with a json string as an initialization parameter

     // Set output mode multiImg, unique mode Others are not supported yet
     NSString *outType = @"multiImg";
    
     // Set action sequence 
     //You must put the silent action HOLDSTILL first and only have one silent action, the following actions can be combined at will.
     NSArray *sequence = @[@"HOLD_STILL", @"BLINK", @"MOUTH", @"NOD", @"YAW"];
    
     // Set detection threshold
     NSArray *threshold = @[@(0.7), @(0.7), @(0.7), @(0.7), @(0.7)];
    
     // autoAntiHack:auto upload encryTarData to server for antiHack checking
     NSDictionary *dictJson = @{@"sequence":sequence,
                                 @"outType":outType,
                               @"threshold":threshold, 
                            @"autoAntiHack": @(NO)}; // NOTE: if you set YES, it will charge with anti hack API
     // Convert to json string
     NSString *strJson = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dictJson options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
     DFActionLivenessController *actionLiveVC = [[DFActionLivenessController alloc] init];
     [actionLiveVC setJsonCommand:strJson];
    
  3. Present action detection view controller

     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:actionLiveVC];
     [navigationController setNavigationBarHidden:YES];
     [self presentViewController:navigationController animated:YES completion:^{
             //If you need to start automatically, not the button trigger, call this line of code
             //[actionLiveVC restart];
     }];
    
  4. Implementation methods: DFActionLivenessDelegate

     // Action detection has started the callback     
     - (void)actionLivenessDidStart;
    
     // Action detecting successfully callback  when set autoAntiHack to NO
     - (void)actionLivenessDidSuccessfulGetData:(NSData *)encryTarData dfImages:(NSArray *)arrDFImage dfVideoData:(NSData *)dfVideoData
     {
         // request for server to upload encryTarData for antihack checking
         // refer to DEMO code
     }
    
     // Action detecting successfully callback  when set autoAntiHack to YES
     - (void)actionLivenessDidSuccessfulGetData:(NSData *)encryTarData
                                       dfImages:(NSArray *)arrDFImage
                                    dfVideoData:(NSData *)dfVideoData
                                         isHack:(BOOL)isHack
     {
         // isHack is the reuslt of server antihack checking
     }
    
     // Action detecting failed callback   
     - (void)actionLivenessDidFailWithType:(DFMultipleLivenessError)iErrorType DetectionType:(DFDetectionType)iDetectionType DetectionIndex:(NSInteger)iIndex Data:(NSData *)encryTarData dfImages:(NSArray *)arrDFImage dfVideoData:(NSData *)dfVideoData;
    
     // Action detecting canceled callback
     - (void)actionLivenessDidCancel;
    

results matching ""

    No results matching ""