Skip to content

iOS SDK Integration ​

Capturing faces for FaceAuthen with the CAKE eKYC iOS SDK, version 1.1.9. The entry point is CakeEkycSdk.

Build Specifications ​

WhatDescription
Xcode16.0+
Target iOS version13+
Swift5

Setup Dependencies ​

Add the SDK frameworks to your target, then declare the camera permission:

xml
<key>NSCameraUsageDescription</key>
<string>Camera access helps us give you a better experience</string>
ruby
pod 'TensorFlowLiteSwift', '2.6.0'
pod 'GoogleMLKit/FaceDetection', '6.0.0'
pod 'PromisesSwift', '~> 2.3.1'
pod 'SnapKit', '~> 5.0.1'

Initialize ​

swift
let config = CESConfig.Builder()
    .withBaseUrl(url: "<BASE_URL>")
    .withToken(tokenProvider: tokenProvider)
    .withLanguage(language: .vi)
    .withLogger(logger: logger)
    .build()

self.cancelable = CakeEkycSdk.getInstance(config: config)
    .receive(on: DispatchQueue.main)
    .sink { [weak self] ekycSdk in
        self?.ekycSdk = ekycSdk
    }

Capture Faces ​

swift
class YourUIViewController: UIViewController, CESFaceCapturingDelegate {
    func onSuccess(result: CESSelfieResult) {}

    func onError(error: CESError) {}

    func onEvent(event: CESEkycEvent) {}

    private func startFace() {
        guard let ekycSdk else { return }
        let config = CESTakeFaceConfig(captureOnly: false, loadingView: loadingView)
        ekycSdk.takeFaces(hostViewController: self, config: config, delegate: self)
    }
}

CESSelfieResult carries the captured faces plus the check results.

FieldTypeDescription
faces[Face]?Captured faces, each with image and gesture.
sanityResult[CESEkycResponse<CESFaceSanityData>]?Sanity response per image.
livenessResultCESEkycResponse<CESFaceLivenessData>?Liveness result.

Take face.image.id from each entry and pass those as the faces array to Register Faces or Verify Face Authen.

Errors ​

FieldTypeDescription
CESError.userCancelled40001User pressed back.
CESError.timeoutError40000Timeout.
CESError.permissionNotGranted40002Permissions were not granted.
CESError.qualityFailed60002 / 60003kErrorCodeFaceSanityFailed or kErrorCodeFaceLivenessFailed.
CESError.unexpectedError50000Runtime exception.

INFO

iOS has no camera-specific error code. 40003 exists only on Android and Flutter — camera failures on iOS surface as unexpectedError.

Upload Image ​

swift
let uploadResult = ekycSdk.upload(image: image, label: "portrait", metaData: metaData)
switch uploadResult {
case .success(data: let uploadResponse):
    debugPrint("success: \(uploadResponse.data?.imageId)")
case .fail(error: let error):
    debugPrint("fail: \(error)")
default: fatalError()
}

Data is also accepted: ekycSdk.upload(data: data, label: "portrait", metaData: metaData).

→ Upload Image

Individual Checks ​

swift
let faceSanity   = ekycSdk.checkFaceSanity(params: CESFaceSanityParams(image: "<IMAGE_ID>"))
let faceLiveness = ekycSdk.checkFaceLiveness(params: CESFaceLivenessParams(images: ["<IMAGE_ID>"]))
let compared     = ekycSdk.compareFaces(params: CESFaceCompareParams(image1: "<IMAGE_ID_1>", image2: "<IMAGE_ID_2>"))

INFO

CESFaceLivenessParams takes images: [String] — pass an array, not a single image.

Next Steps ​

Developers