iOS client integration
The Real-Person Verification service provides an iOS client SDK to help you implement the face authentication feature in your app. You can call the request for mobile client-based verification and authentication API to obtain a unique VerificationToken for real-person verification, which you then use to launch the Real-Person Verification client SDK. This topic provides detailed instructions and code examples.
For questions about API integration, usage, or other issues related to the AI capabilities of the Alibaba Cloud Vision AI Platform, contact us by joining our DingTalk group (ID: 23109592).
Prerequisites
-
Your app must run on a physical device running iOS 9.0 or later.
-
You must use Objective-C++ to integrate the Real-Person Verification service.
SDK and demo code
-
Download the iOS SDK.
-
Download the iOS Demo.
After downloading the iOS Demo, you must modify the bundle identifier.
For security reasons, the SDK cannot be run on a simulator.
Development setup
-
Configure the camera permission request in your
Info.plistfile.Add a key named
Privacy - Camera Usage Descriptionwith the type String. For the value, provide a message that explains why your app needs camera access. For example: "This app requires camera access to perform face authentication." -
In your Xcode build settings, disable the Bitcode option.
-
In your Xcode build settings, navigate to Linking > Other Linker Flags and add the -ObjC flag.
Resource files
Select your TARGETS, go to the Build Phases tab, and add the following four bundles to Copy Bundle Resources:
-
APBToygerFacade.bundle: Located in APBToygerFacade.framework.
-
BioAuthEngine.bundle: Located in BioAuthEngine.framework.
-
OCRXMedia.bundle: Located in OCRDetectSDKForTech.framework.
-
ToygerService.bundle: Located in ToygerService.framework.
Dependencies
After downloading the iOS SDK (the SDK is a framework package), add the SDK package and additional system library dependencies to Link Binary With Libraries in Xcode. The details are as follows:
-
SDK packages
APBToygerFacade APPSecuritySDK BioAuthEngine DTFIdentityManager DTFMobileRPC DTFUtility OCRDetectSDKForTech ToygerNative ToygerService VerifyNativeAbility ZolozFaceAuthFacade AliyunDevicePKG -
System library dependencies
CoreGraphics.framework Accelerate.framework SystemConfiguration.framework AssetsLibrary.framework CoreTelephony.framework QuartzCore.framework CoreFoundation.framework CoreLocation.framework ImageIO.framework CoreMedia.framework AVFoundation.framework WebKit.framework libresolv.tbd libz.tbd libc++.1.tbd libc++abi.tbd AudioToolbox.framework CFNetwork.framework MobileCoreServices.framework libz.1.2.8.tbd AdSupport.framework
Calling the SDK
-
Import the header file.
#import <ZolozFaceAuthFacade/ZolozFaceAuthFacade.h> -
Initialize the SDK.
The code to initialize the SDK is as follows:
[ZolozFaceAuthFacade init];This initialization method improves the user experience by preloading necessary data for face authentication. This method runs asynchronously and does not block the main thread. We recommend calling it in the
application:didFinishLaunchingWithOptions:function of your app delegate:-(BOOL)application:(UIApplication)application didFinishLaunchingWithOptions:(NSDictionary)launchOptions -
Get the metainfo data.
[ZolozFaceAuthFacade getMetaInfo];The returned value is an NSDictionary. Your mobile client must convert it to a JSON string and pass this string to the MetaInfo parameter when calling the request for mobile client-based verification and authentication API.
-
Start the verification.
-
Call the SDK.
[ZolozFaceAuthFacade verifyWith:self.verificationToken extParams:extParams onCompletion:^(ZIMResponse *response) {}]; -
Parameters
-
verificationToken: An
NSStringobject. Obtain this value from the VerificationToken parameter returned by the request for mobile client-based verification and authentication API.NoteThe
VerificationTokenreturned by the request for mobile client-based verification and authentication API is valid for 30 minutes from the time it is generated. Attempting to start face authentication with an expired token causes an error. Ensure you complete the verification within this time frame. -
extParams: An
NSDictionaryobject. You must pass the current view controller in this dictionary. The SDK uses it to display a loading indicator and present the verification view controller.[extParams setValue:self forKey:@"currentCtr"];(Optional) Return a video: To record a video of the verification process, add the
returnVideokey with a value oftrueto theextParamsdictionary. TheverifyWithmethod then saves the video to the path specified in thevideoFilePathfield of theZIMResponseobject returned by theverifyWithmethod.[extParams setValue:@"true" forKey:@"returnVideo"];
-
-
Sample code
[ZolozFaceAuthFacade verifyWith:self.verificationToken extParams:extParams onCompletion:^(ZIMResponse *response) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *title = @"Success"; switch (response.code) { case 1000: break; case 1001: title = @"System Error"; break; case 1003: title = @"User Canceled"; break; case 2002: title = @"Network Error"; break; case 2006: title = @"Verification Failed"; break; case 2003: title = @"Incorrect Device Time"; break; default: break; } }); }]; -
The
response.codeproperty is an integer and has the following possible values:Code
Error code
Description
1000
ZIMResponseSuccess
Indicates that the face authentication was successful. This result is for reference only. To get the final verification result, call the query of mobile client-based verification and authentication API.
1001
ZIMInternalError
Indicates a system error.
1003
ZIMInterrupt
Indicates that the user canceled the verification.
2002
ZIMNetworkfail
Indicates a network error.
2003
ZIMTIMEError
Indicates that the device time is incorrect.
2006
ZIMResponseFail
Indicates that the face authentication failed. To obtain detailed failure reasons, call the query of mobile client-based verification and authentication API.
For more information, see iOS client error codes.
[ZolozFaceAuthFacade verifyWith:self.verificationToken extParams:extParams onCompletion:^(ZIMResponse *response) {}];response.imageContentData: The captured face image data, returned as an
NSDataobject. This value is nil if the user cancels the process or if the operation times out. When uploading the image from the client, do not compress or resize theNSDataobject. The service performs an MD5 check on the image, and any modification will cause this check to fail. The following example shows how to convert theNSDataobject to an image:UIImage* newImage = [UIImage imageWithData:response.imageContentData];response.reason and response.retMessageSub: Strings that provide more details about the authentication result or failure.
-
App Store submission
When submitting your app to the App Store, you must include descriptions for the following required permissions in your Info.plist file. Failure to do so will result in your app being rejected:
-
Camera permission: You must add a description for the
Privacy - Camera Usage Descriptionkey in yourInfo.plistfile. -
IDFA permission: You must add a description for the
NSUserTrackingUsageDescriptionkey in yourInfo.plistfile. For example: "This permission is used only to identify the device, secure the real-person verification process, and improve service experience. It will not be used to track your activity across other companies' apps or websites."