Source Code

import UIKit
import CafFaceLiveness

class MainViewController: UIViewController {
    private var sdk: CafFaceLivenessSDK?

    override func viewDidLoad() {
        super.viewDidLoad()
        setupCafFaceLiveness()
        
        let startLivenessButton = UIButton(type: .system)
        startLivenessButton.setTitle("Start Liveness Detection", for: .normal)
        startLivenessButton.addTarget(self, action: #selector(startLivenessDetection), for: .touchUpInside)
        view.addSubview(startLivenessButton)
        
        // Setup layout constraints for button (if needed)
    }

    private func setupCafFaceLiveness() {
        sdk = CafFaceLivenessSDK.CafFaceLivenessBuilder()
            .setStage(.prod)
            .setImageUrlExpirationTime("2H")
            .setLoadingScreen(withLoading: true)
            .build()
        
        sdk?.delegate = self
    }

    @objc private func startLivenessDetection() {
        sdk?.startSDK(
            viewController: self,
            mobileToken: "mobileToken",
            personId: "personId",
            debugEnabled: true
        )
    }
}

// MARK: - CafFaceLivenessDelegate

extension MainViewController: 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