> For the complete documentation index, see [llms.txt](https://docs.caf.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.caf.io/caf-sdk/caf-sdk-pt-br/ios/standalone-modules/caffaceauth/start-sdk.md).

# Iniciar o SDK

### Instanciando o SDK

Primeiro, instancie um objeto do tipo `CafFaceAuthSDK`. Este objeto é para você configurar todas as suas regras de negócio:

```swift
class CafFaceAuthViewController: UIViewController {
    var faceAuthenticator: FaceAuthSDK?

    func setupFaceAuthenticator() {
        faceAuthenticator = FaceAuthSDK.Builder()
        // a tabela abaixo mostra todas as opções de configuração do SDK
        .build()
        faceAuthenticator?.delegate = self
    }

    func startFaceAuthenticator() {
        faceAuthenticator?.startFaceAuthSDK(viewController: self, mobileToken:"yourMobileToken", personId: "personId")
    }
}
```

### Obtendo os Resultados

Você deve implementar a `FaceAuthSDKDelegate` classe para obter os resultados do SDK. Para isso, você deve fornecer um `UIViewController` à sua instância do SDK:

```swift
faceAuthenticator?.delegate = self
```

#### Implementação do Delegate

O delegate abaixo deve ser implementado para tratar os resultados do SDK. Ao implementar a extensão do delegate, você terá acesso a um objeto dependendo do tipo de retorno. Em cada caso, o objeto carrega informações diferentes.

```swift
extension FaceAuthViewController: FaceAuthSDKDelegate {
  func didFinishSuccess(with faceAuthenticatorResult: CafFaceAuth.FaceAuthenticatorResult) {
    //tratar o resultado de sucesso
  }
    
  func didFinishWithError(with faceAuthenticatorErrorResult: CafFaceAuth.FaceAuthenticatorErrorResult) {
    //tratar o resultado de erro
  }
    
  func didFinishFaceAuthWithCancelled() {
    //tratar quando o usuário fecha o SDK
  }
    
  func openLoadingScreenStartSDK() {
    //tratar tela de carregamento - exibir
  }
    
  func closeLoadingScreenStartSDK() {
    //tratar tela de carregamento - fechar
  }
    
  func openLoadingScreenValidation() {
    //tratar tela de carregamento - exibir
  }
    
  func closeLoadingScreenValidation() {
    //tratar tela de carregamento - fechar
  }
}   
```

#### Tela de Carregamento

Para criar uma tela de carregamento durante os processos de validação do SDK, você precisa implementar uma view com a tela de carregamento e exibi-la nas *abertas* e *fechar* funções do delegate. `openLoadingScreenStartSDK()`, `closeLoadingScreenStartSDK()`, `openLoadingScreenValidation()`, `closeLoadingScreenValidation()`

Na implementação do SDK, é necessário adicionar a view à pilha de views usando o código a seguir. Isso torna a view visível.

```swift
view.addSubview(loadingHUD)
```

Esta view deve ser adicionada antes do Builder do SDK.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.caf.io/caf-sdk/caf-sdk-pt-br/ios/standalone-modules/caffaceauth/start-sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
