Building the SDK

Creating a Liveness SDK instance

In order to create an instance of CafFaceLivenessSDK, we need to use our CafFaceLivenessBuilder. This allows you to configure all necessary configurations.

Builder Methods

Parameter
Required
Description

setStage(CAFStage)

No

Defines the environment stage (e.g., .prod, .beta). Default is .prod.

setImageUrlExpirationTime(String)

No

Sets the expiration time for the image URL used in the scan capture. Default is "3H".

setLoadingScreen(Bool)

No

Enables or disables the default loading screen during SDK loading events. Default is false.

delegate = self

Yes

Sets the delegate to handle liveness verification events.

Example

    private var sdk: CafFaceLivenessSDK?

private func setupCafFaceLiveness() {
    sdk = CafFaceLivenessSDK.CafFaceLivenessBuilder()
        .setStage(.prod)
        .setImageUrlExpirationTime("2H")
        .setLoadingScreen(withLoading: true)
        .build()
    
    sdk?.delegate = self
    sdk?.startSDK(viewController: self, mobileToken: "your_mobile_token", personId: "your_person_id")
}

// MARK: - CafFaceLivenessDelegate

extension YourViewController: CafFaceLivenessDelegate {
    func didFinishWithSuccess(livenessResult: CafLivenessResult) {
        print("Success: \(livenessResult.signedResponse ?? "No response")")
    }

    func cancelled() {
        print("Liveness detection cancelled")
    }

    func didFinishWithError(sdkFailure: CafSDKFailure) {
        print("Error: \(sdkFailure.description ?? "Unknown error")")
    }

    func loading() {
        print("Liveness detection loading")
    }

    func loaded() {
        print("Liveness detection loaded")
    }
}

Last updated