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
Quick Integration
Before you use the SDK, you need to integrate it into your development environment first.
Configuration development environment
1. Import SDK package
Copy the libDFSilentLiveness folder (including libDFSilentLivenessDetector.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.
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.
2.2 Need to manually close Bitcode
Step: TARGETS -> BuildSettings -> Enable Bitcode: Set NO.
3. Add related reference library
Step: TARGETS ->Build Phases: Add related reference library
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
DFSilentfaceViewController Call Flow
DFSilentfaceViewController is an example of the silent liveness detection SDK we provide. You can set detection threshold, detection group, etc. Once setup is complete, you can start detecting.
The details are as follows:
Compliance with the protocol: DFSilentLivenessDetectorDelegate
@interface ViewController () <DFSilentLivenessDetectorDelegate>
Get resource path
NSString *strResourcesBundlePath = [[NSBundle mainBundle] pathForResource:@"df_liveness_resource" ofType:@"bundle"];
Get the authorization file path
NSString *licensePath = [[NSBundle mainBundle] pathForResource:@"DFLicense" ofType:@""];
Initialize the action liveness detection view controller
DFSilentfaceViewController *livenessVC = [[DFSilentfaceViewController alloc] initWithResourcesBundlePath:strResourcesBundlePath licensePath:licensePath];
Parameter settings
// Set detection threshold, track miss, group count - (void)setThreshold:(float)threshold groupCount:(NSInteger)groupCount;
// Set callback delegate and thread queue - (void)setDelegate:(id <DFSilentLivenessDetectorDelegate>)delegate callBackQueue:(dispatch_queue_t)queue;
Present action detection view controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:livenessVC]; [navigationController setNavigationBarHidden:YES]; [self presentViewController:navigationController animated:YES completion:nil];
Implementation methods: DFSilentLivenessDetectorDelegate
- (void)livenessDidStart; { // Silent detection has started callback }
// Silent 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 // successScore: The confidence of the last successful frame is detected(deprecated). - (void)livenessDidSuccessfulGetData:(NSData *)data dfImages:(NSArray *)arrDFImage successScore:(float)successScore; { }
// Silent detecting failed callback - (void)livenessDidFailWithErrorType:(LivefaceErrorType)iErrorType { }
// Silent detecting canceled callback - (void)livenessDidCancel { }
DFLivenessController Call Flow
DFLivenessController is written on DFSilentfaceViewController that has some default logic. If you don't have customization requirements, you can use DFActionLivenessController directly.
Compliance with the protocol: DFLivenessDetectorDelegate
@interface ViewController () <DFLivenessDelegate>
Initialization parameter setting
// autoAntiHack:auto upload encryptData to server for antiHack checking DFLivenessController is init with a json string as an initialization parameter. NSDictionary *dictJson = @{@"groupCount": @(2), @"threshold": @(0.8), @"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]; DFLivenessController * livenessVC = [[DFLivenessController alloc] init]; [livenessVC setJsonCommand:strJson];
Present silent detection view controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:livenessVC]; [navigationController setNavigationBarHidden:YES]; [self presentViewController:navigationController animated:YES completion:^{ //If you need to start automatically, not the button trigger, call this line of code //[livenessVC restart]; }];
Implementation methods: DFLivenessDelegate
// Action detection has started the callback - (void)livenessDidStart;
// Action detecting successfully callback when set autoAntiHack to NO // Return the encrypted binary data、images、The confidence of the last successful frame is detected(deprecated) - (void)livenessDidSuccessfulGetData:(NSData *)encryTarData dfImages:(NSArray *)arrDFImage successScore:(float)successScore { // request for server to upload encryTarData for antihack checking // refer to DEMO code }
// Action detecting successfully callback when set autoAntiHack to YES // Return the encrypted binary data、images、The confidence of the last successful frame is detected(deprecated)、 is hack or not - (void)livenessDidSuccessfulGetData:(NSData *)encryTarData dfImages:(NSArray *)arrDFImage successScore:(float)successScore isHack:(BOOL)isHack { // isHack is the reuslt of server antihack checking }
// Action detecting failed callback - (void)livenessDidFailWithType:(DFLivenessError)iErrorType;
// Action detecting canceled callback - (void)livenessDidCancel;