All Products
Search
Document Center

ID Verification:iOS client SDK

Last Updated:Dec 10, 2024

ID Verification provides a client SDK for iOS to help you implement electronic Know Your Customer (eKYC) capabilities in your mobile app. You can call the Initialize operation to obtain a unique transaction ID and use the transaction ID to start the client SDK. This topic describes how to integrate ID Verification client SDK for iOS with a mobile app and provides the sample code.

Limits

  • The SDK supports only iPhones or iPads that run iOS 9 or later.

  • The permissions on the network and camera must be granted to the SDK.

Download and configure the SDK

Obtain the SDK

Download the SDK for iOS, decompress the SDK package, and then copy all framework packages to your project folder.

Add the required permissions

Add the required permission in the Info.plist file. The permission description is for reference only.

image

Add frameworks to Xcode

In the settings of the project, choose Build Settings > Build Phases > Link Binary With Libraries. Then, add frameworks.

  • Add all frameworks in the SDK.

    AliyunIdentityFace.framework
    AliyunIdentityPlatform.framework
    AliyunIdentityUtils.framework
    AliyunIdentityOcr.framework
    ToygerService.framework
    AliyunOSSiOS.framework
    faceguard.framework
    DTFUtility.framework
    ToygerNative.framework
  • Add system dependencies.

    AudioToolbox.framework
    CoreMedia.framework
    AVFoundation.framework
    SystemConfiguration.framework
    UIKit.framework
    CoreTelephony.framework
    CoreMotion.framework
    Accelerate.framework
    libresolv.tbd
    libsqlite3.tbd
    libc++.tbd
    libz.tbd

Copy resource files

In the settings of the project, choose Build Settings > Build Phases > Copy Bundle Resources. Then, copy resource files.

  • AliyunIdentityPlatform.bundle: The resource resides in AliyunIdentityPlatform.framework.

  • AliyunIdentityFace.bundle: The resource resides in AliyunIdentityFace.framework.

  • AliyunIdentityOCR.bundle: The resource resides in AliyunIdentityOcr.framework.

  • ToygerService.bundle: The resource resides in ToygerService.framework.

Configure linker flags

In the settings of the project, choose Other Linker Flags > Build Settings and add the -ObjC flag.

Use the SDK

Import the header file

#import <AliyunIdentityPlatform/AliyunIdentityPlatform.h>

Initialize the SDK

- (void)install;

Obtain metaInfo

- (NSString *)getMetaInfo;

The app server must obtain the metaInfo of a client before the app server can call the Initialize operation.

Therefore, the client must obtain the metaInfo from the local device and then use the metaInfo to complete the subsequent initialization process to obtain a transaction ID.

Perform verification

- (void)verifyWithCertifyId:(NSString *)certifyId
  withCurrentViewController:(UIViewController *)viewController
              withExtParams:(NSDictionary *)extParams
                   complete:(AliyunIdentityVerifyBlock)completeBlock;

Parameters

Parameter

Type

Description

transactionId

NSString

The transaction ID that is returned by the Initialize operation.

viewController

UIViewController

The current viewController of your client app.

extParams

NSDictionary

The extended parameters. In most cases, set this parameter to null.

For more information about the parameters that you can specify in extParams, see the extParams section of this topic.

completeBlock

AliyunIdentityVerifyBlock

The callback function. The verification result is returned.

extParams

Key

Description

Example value (string)

kIdentityParamKeyNextButtonColor

The color of the button at the bottom of the optical character recognition (OCR) result page.

#FF0000

kIdentityParamKeyRoundProgressColor

The color of the progress circle for liveness detection.

#FF0000

kIdentityParamKeyOcrSelectPhoto

Specifies whether to display the entry for uploading a photo from the album during document OCR. Valid values:

  • 1 (default): yes.

  • 0: no.

1

kIdentityParamKeyShowOcrResult

Specifies whether to display the OCR result screen during document OCR. Valid values:

  • 1 (default): yes.

  • 0: no.

1

kIdentityParamKeyMaxRetryCount

The maximum number of retries that are allowed. Valid values: 3 to 10. Default value: 10.

10

kIdentityParamKeyCardOcrTimeOutPeriod

The timeout period of document OCR. Valid values: 20 to 60. Default value: 20. Unit: seconds.

20

kIdentityParamKeyFaceVerifyTimeOutPeriod

The timeout period of liveness detection. Valid values: 20 to 60. Default value: 20. Unit: seconds.

20

kIdentityParamKeyCardOcrEditTimeOutPeriod

The timeout period for displaying the OCR result page. Valid values: 60 to 180. Unit: seconds. By default, the OCR result page does not time out.

180

kIdentityParamKeyLanguage

The custom language setting of the SDK. By default, the value of this parameter is determined by the language setting of your mobile device.

Valid values:

  • zh-Hans: simplified Chinese.

  • zh-Hant: traditional Chinese.

  • en: English.

  • ja: Japanese.

  • ko: Korean.

  • id: Indonesian.

  • ms: Malay.

  • th: Thai.

  • vi: Vietnamese.

kIdentityParamKeyDefaultLanguage

The default language setting of the SDK. You can refer to the valid values of kIdentityParamKeyLanguage.

Default value: en.

en

kIdentityParamKeyCloseButtonPosition

The position of the button that you can click to stop the SDK. Valid values:

  • left (default)

  • right

left

Add a language

To add a custom language, perform the following steps:

  1. Find the example_face_liveness.strings file in AliyunIdentityPlatform.bundle in AliyunIdentityPlatform.framework.

  2. Translate the strings in the example_face_liveness.strings file to the language that you want to use and save the file as language.strings. Replace language in the file name with the language code of the language that you want to use.

  3. Specify the language in your code by setting the kIdentityParamKeyLanguage parameter to the language code.

Error codes

Error code

Billed

Description

1000

Yes

The customer completed the face verification process, and the verification result was successful. This result is for reference only. You can call the server query operation CheckResult to obtain the final verification result and proceed to the next step.

1001

Yes

The customer completed the face verification process, and the verification result was failed. This result is for reference only. You can call the server query operation CheckResult to obtain the final verification result and the detailed cause for the failure, and then proceed to the next step.

1002

No

A system error occurred.

1003

No

The SDK failed to be initialized. Check whether the client time is valid.

1004

No

A camera error occurred. To fix the error, perform the following operations:

  1. Check whether your app has camera permissions before verification.

  2. If your app has camera permissions but the no-permission error persists, clear the cache of the app and try again.

1005

No

A network error occurred.

1006

No

The customer unexpectedly exited.

1007

No

The transaction ID is invalid.

1009

No

The timestamp of the client is invalid.

1011

No

The specified document type does not match the submitted document.

1012

No

The critical information is missing after document verification or the format verification failed.

1013

No

The image quality does not meet the requirements.

1014

No

The number of errors exceeds the upper limit.

Sample code

#import "ViewController.h"
#import <AliyunIdentityPlatform/AliyunIdentityPlatform.h>

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    // Initialize the sdk
    [[AliyunIdentityPlatform sharedInstance] install];
 
    [self initUI];
}

// This function needs to be implemented by the user
- (NSString *)sentMetaInfoAndGetTransactionId:(NSString*) metaInfo {
    return @"Get TransactionId from your server."; // replace it.
}

- (void)onClickStart:(id) sender {
    NSString *metaInfo = [[AliyunIdentityPlatform sharedInstance] getMetaInfo];
    NSString *transactionId = [self sentMetaInfoAndGetTransactionId:metaInfo];

    // Set the sdk language
    NSDictionary *extParams = @{
        kIdentityParamKeyLanguage:@"en"
    };
    // start Verify
    [[AliyunIdentityPlatform sharedInstance] verifyWithCertifyId:transactionId
                                       withCurrentViewController:self
                                                   withExtParams:extParams
                                                        complete:^(AliyunIdentityVerifyRes *response) {
        NSString *resContent = [NSString stringWithFormat:@"Code=%d Message=%@", response.code, response.message];
    }];
}

- (void)initUI {
    // ......
}

@end

Demo

You can download the demo for iOS to experience the SDK.