All Products
Search
Document Center

ID Verification:iOS

Last Updated:Apr 08, 2024

ID Verification provides a client SDK for iOS to help you implement electronic Know Your Customer (eKYC) features in your business application. You can call the Initialize operation to obtain a unique transactionId and use the transactionId to start the client SDK. This topic describes how to integrate ID Verification client SDK for iOS with an application 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 iOS_SDK, decompress the SDK package, and then copy all framework packages to your project folder.

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
    APMUtils.framework
    faceguard.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 the ToygerService.framework.

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

Configure linker flags

In the setting 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 client application must send the metaInfo to your business server to initialize the SDK for iOS. Then, the server calls the Initialize operation to obtain a transactionId and returns the transactionId to your client application.

Perform authenticationfor iOS

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

Parameters

Parameter

Type

Description

transactionId

NSString *

The transactionId that is returned by the Initialize operation.

viewController

UIViewController *

The current viewController of your client application.

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 that is fired when the authentication ends.

extParams

Key

Description

Example string type

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": yes. This is the default value.

  • "0": no.

"1"

kIdentityParamKeyShowOcrResult

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

  • "1": yes. This is the default value.

  • "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 the same as 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. Default value: "en".

"en"

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

Description

1000

The authentication was successful. This result is only for reference. You can call the CheckResult operation to obtain the final authentication result.

1001

The authentication failed. You can call the CheckResult operation to query the detailed cause of the failure.

1002

A system error occurred.

1003

Failed to initialize the SDK. Check whether the time is correct on the client.

1004

A camera error occurred. You can perform the following steps to resolve the error:

  1. Before you perform authentication, make sure that the application has the camera permission.

  2. If the error persists, clear the cache of the application and try again.

1005

A network error occurred.

1006

The user exists during the authentication.

1007

Invalid transactionId.

1009

Invalid client timestamp.

1011

Invalid document type.

1012

Key information is missing in the recognized document or the format is invalid.

1013

Poor image quality.

1014

The maximum number of errors is exceeded.

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:_certifyId
 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.