> 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/ios/standalone-modules/deprecated-sdks/faceauthenticator-deprecated.md).

# FaceAuthenticator (Deprecated)

## **Required permissions**

In the **`info.plist`** file, add the permissions below:

<table data-header-hidden><thead><tr><th width="402"></th><th width="228.33333333333331"></th><th></th></tr></thead><tbody><tr><td><strong>Permission</strong></td><td><strong>Reason</strong></td><td><strong>Required?</strong></td></tr><tr><td><strong><code>Privacy - Camera Usage Description</code></strong></td><td>To capture the user selfie</td><td>Yes</td></tr></tbody></table>

## **Utilization**

First, instantiate an object of type **`FaceAuthenticator`**:

```swift
let faceAuthenticator = FaceAuthenticator.Builder(mobileToken: "mobileToken")
    // see the table below
    .build()
```

### **FaceAuthenticator.Builder**

| **Parameter**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | **Required?**                                                                                                                                                                                          |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong><code>String mobileToken</code></strong></p><p>Usage token associated with your CAF account</p>                                                                                                                                                                                                                                                                                                                                                                                                                                | Yes                                                                                                                                                                                                    |
| <p><strong><code>.setPeopleId(\_ peopleId: String)</code></strong></p><p>Identifier of the user in which is registered the face of the user who will perform the facematch. Currently, this value only accepts the user's CPF</p>                                                                                                                                                                                                                                                                                                         | Yes                                                                                                                                                                                                    |
| <p><strong><code>.setAnalyticsSettings(useAnalytics: Bool)</code></strong></p><p>Enables/disables data collection for <a href="https://github.com/combateafraude/public-docs/blob/docs-sdks/analytics.md">analytics</a></p>                                                                                                                                                                                                                                                                                                               | No. The default is **`true`**                                                                                                                                                                          |
| <p><strong><code>.setStabilitySensorSettings(message: String?, stabilityThreshold: Double?)</code></strong></p><p>Changes the default settings of the stability sensor. The threshold of this sensor is in the range of the last two accelerations collected from the device.</p>                                                                                                                                                                                                                                                         | No. The default is "Keep the phone still" and 0.3, respectively                                                                                                                                        |
| <p><strong><code>.setLayout(layout: PassiveFaceLivenessLayout)</code></strong></p><p>Changes the document masks for success, failure and normal.</p><p>Also allows you to change the sound and cancel buttons, which are at the top of the screen</p>                                                                                                                                                                                                                                                                                     | No                                                                                                                                                                                                     |
| <p><strong><code>.setColorTheme(color: UIColor)</code></strong></p><p>Change the color of the sound and cancel buttons that are at the top of the screen. Also change the color of the popup buttons, inflated before each document.</p>                                                                                                                                                                                                                                                                                                  | No                                                                                                                                                                                                     |
| <p><strong><code>.enableSound(enableSound: Bool)</code></strong></p><p>Enables/disables sounds and the sound icon in the SDK</p>                                                                                                                                                                                                                                                                                                                                                                                                          | No. The default is **`true`**                                                                                                                                                                          |
| <p><strong><code>.setNetworkSettings(requestTimeout:TimeInterval)</code></strong></p><p>Change the default network settings</p>                                                                                                                                                                                                                                                                                                                                                                                                           | No. The default is 60 (seconds)                                                                                                                                                                        |
| <p><strong><code>.setImageCaptureSettings(beforePictureInterval: TimeInterval!, enableManualCapture: Bool, timeManualCapture: TimeInterval)</code></strong></p><p>Allows you to set the capture per image. The beforePictureInterval attribute sets the time the user should stay with the face docked in the mask. The <strong><code>enableManualCapture</code></strong> attribute enables or disables manual capture. And <strong><code>timeManualCapture</code></strong> defines the time at which manual capture will be enabled.</p> | No. The default is enabled. For beforePictureInterval the default is 2 (seconds). For **`enableManualCapture`** the default is **`true`** and for **`timeManualCapture`** the default is 10 (seconds). |
| <p><strong><code>.setVideoCaptureSettings(time: TimeInterval)</code></strong></p><p>Video capture setting method</p>                                                                                                                                                                                                                                                                                                                                                                                                                      | No                                                                                                                                                                                                     |
| <p><strong><code>.setEyesClosedSettings(threshold: Double, isEnable: Bool, errorMessage: String)</code></strong></p><p>Allows to customize the SDK's eyes closed validation settings. The method takes as parameter <strong><code>isEnable</code></strong> to enable or disable the validation, <strong><code>threshold</code></strong>, value between 0.0 and 1.0, and errorMessage, to set the message in case closed eyes are detected.</p>                                                                                            | No. The default is **`true`**, 0.5 is "Don't wear sunglasses and keep your eyes open".                                                                                                                 |
| <p><strong><code>.setStage(stage: CAFStage)</code></strong></p><p>Allows you to choose the environment in wich the SDK will run (production, beta). The method takes as parameter an enum <strong><code>CAFStage</code></strong> to select the environment:</p>                                                                                                                                                                                                                                                                           | No. The default is **`.PROD`**                                                                                                                                                                         |
| **Enum**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Description**                                                                                                                                                                                        |
| **`.PROD`**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Will use the Trust Platform **production** environment to register the SDK executions.                                                                                                                 |
| **`.BETA`**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Will use the Trust Platform **beta** environment to register the SDK executions.                                                                                                                       |

{% hint style="warning" %}
Each environment (beta and production) requires its own specific mobileToken, generated in the Trust platform of the respective environment.
{% endhint %}

After creating the **`FaceAuthenticator`** type object, you can start the **`FaceAuthenticatorController`** by passing it as a parameter in the constructor:

```swift
let faceAuthController = FaceAuthenticatorController(faceAuthenticator: faceAuthenticator)
faceAuthController.faceAuthenticatorDelegate = self
present(faceAuthController, animated: true, completion: nil)
```

## **Getting the result**

To get the result, you must implement the **`FaceAuthenticatorControllerDelegate`** delegate in your controller:

```swift
class YouController: UIViewController, FaceAuthenticatorControllerDelegate{
    
    // MARK: Delegates Face Auht
    
    func faceAuthenticatorController(_ faceAuthenticatorController: FaceAuthenticatorController, didFinishWithResults results: FaceAuthenticatorResult) {
        //Called when the process was successfully executed
        //The result variable contains the data obtained
    }
    
    func faceAuthenticatorControllerDidCancel(_ faceAuthenticatorController: FaceAuthenticatorController) {
        //Called when the process was canceled by the user
    }
    
    func faceAuthenticatorController(_ faceAuthenticatorController: FaceAuthenticatorController, didFailWithError error: FaceAuthenticatorFailure) {
        //Called when the process terminate with an error
        //The error variable contains info about error
    }
}
```

### **FaceAuthenticatorResult**

<table data-header-hidden><thead><tr><th width="530"></th><th></th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td><strong>Can it be null?</strong></td></tr><tr><td><p><strong><code>authenticated: Bool</code></strong></p><p>Flag indicating whether the user's selfie passed the facematch with the photo stored on the CAF server with the respective CPF</p></td><td>No</td></tr><tr><td><p><strong><code>signedResponse: String</code></strong></p><p>Signed response from the CAF server that performed the facematch. Use this parameter if you want an extra layer of security by checking that the signature of the response is not broken, caused by an intercepted request. If it is broken, there is a strong indication of request interception</p></td><td>Yes, in case of error</td></tr><tr><td><p><strong><code>trackingId: String?</code></strong></p><p>Identifier of this run on our servers. If possible, save this field and send it along to our API. This way we will have more data about how the user behaved during the execution</p></td><td>Yes, if the user sets <strong><code>useAnalytics = false</code></strong> or the analytics calls do not work</td></tr><tr><td><p><strong><code>lensFacing: Int</code></strong></p><p>Defines the face of the camera that was used. Use <strong><code>FaceAuthenticatorResult.LENS_FACING_FRONT</code></strong> or <strong><code>FaceAuthenticatorResult.LENS_FACING_FRONT</code></strong> to validate.</p></td><td>No</td></tr></tbody></table>

### **FaceAuthenticatorFailure**

Superclass that leads to the SDK shutdown. To find out what the reason was, find out which object class has the **`isKindOfClass()`** method, equivalent to **`instanceof`** in Java and **`is`** in Dart:

<table data-header-hidden><thead><tr><th width="236.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>isKindOfClass()</strong></td><td><strong>Description</strong></td><td><strong>Example</strong></td></tr><tr><td><strong><code>InvalidTokenReason</code></strong></td><td>The token entered is not valid for the corresponding product</td><td>Parameterize "test123" as token in the SDK builder</td></tr><tr><td><strong><code>PermissionReason</code></strong></td><td>You are missing some mandatory permission to run the SDK</td><td>Start DocumentDetector without camera permission granted</td></tr><tr><td><strong><code>NetworkReason</code></strong></td><td>Internet connection failure</td><td>User was without internet during facematch in FaceAuthenticator</td></tr><tr><td><strong><code>ServerReason</code></strong></td><td>When an SDK request receives a status code of failure</td><td>In theory, it shouldn't happen. If it does, let us know!</td></tr><tr><td><strong><code>StorageReason</code></strong></td><td>There is no space on the user device's internal storage</td><td>When there is no space on the internal storage while capturing the document photo</td></tr><tr><td><strong><code>InvalidFaceReason</code></strong></td><td>There is no face record for the given <strong><code>peopleId</code></strong></td><td>When the user authenticates with a <code>peopleId</code> that has no face record</td></tr></tbody></table>

## **Examples**

### **Customizing the Layout**

You can customize the layout by creating an object of type **`FaceAuthenticatorLayout`** and passing it as a parameter to the **`FaceAuthenticatorBuilder`**:

```swift
let layout = FaceAuthenticatorLayout()

layout.changeMaskImages(
    greenMask: UIImage(named: "my_green_mask"),
    whiteMask: UIImage(named: "my_white_mask"),
    redMask: UIImage(named: "my_red_mask"))

layout.changeSoundImages(soundOn: UIImage(named: "my_sound_on_image"),
                        soundOff: UIImage(named: "my_sound_off_image"))

layout.closeImage = UIImage(named: "my_close_image")
layout.buttonSize = CGFloat(50)
layout.buttonContentMode = .scaleAspectFill

let faceAuthenticatorConfiguration = FaceAuthenticatorBuilder(apiToken: "API_TOKEN")
    .setLayout(layout: layout)
    .build()
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.caf.io/caf-sdk/ios/standalone-modules/deprecated-sdks/faceauthenticator-deprecated.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
