For the complete documentation index, see llms.txt. This page is also available as Markdown.

Código-fonte

import UIKit
import CafFaceLiveness

class MainViewController: UIViewController {
    private var sdk: CafFaceLivenessSDK?

    override func viewDidLoad() {
        super.viewDidLoad()
        setupCafFaceLiveness()
        
        let startLivenessButton = UIButton(type: .system)
        startLivenessButton.setTitle("Iniciar detecção de liveness", for: .normal)
        startLivenessButton.addTarget(self, action: #selector(startLivenessDetection), for: .touchUpInside)
        view.addSubview(startLivenessButton)
        
        // Configurar as restrições de layout para o botão (se necessário)
    }

    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
        )
    }
}

// MARCA: - CafFaceLivenessDelegate

extension MainViewController: CafFaceLivenessDelegate {
    func didFinishWithSuccess(livenessResult: CafLivenessResult) {
        print("Sucesso: \(livenessResult.signedResponse ?? "Sem resposta")")
    }

    func cancelled() {
        print("Detecção de liveness cancelada")
    }

    func didFinishWithError(sdkFailure: CafSDKFailure) {
        print("Erro: \(sdkFailure.description ?? "Erro desconhecido")")
    }

    func loading() {
        print("Detecção de liveness carregando")
    }

    func loaded() {
        print("Detecção de liveness carregada")
    }
}

Atualizado