> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/ios-sdk/ajustes-avanzados.md).

# Advanced settings

This section provides more information about the [Simplified Launch](https://docs.facephi.com/docs.facephi-en/sdks/sdk-mobile/ios-sdk/inicializacion/lanzamiento-simplificado.md).

### Add a private repository

To access our private repository, you must first have installed **Cocoapods** on the machine.

For security and maintenance reasons, new ***SDKMobile*** components are stored in private repositories that require specific credentials to access. You can obtain these credentials from the Facephi support team. The following instructions explain how to prepare your environment to use the components:

* First, install the command that will let us use cocoapods with **Artifactory**.

```
sudo gem install cocoapods-art
```

* On a Mac with an **M1 chip** you may encounter errors during installation; if so, use the following command:

```
sudo arch -arm64 gem install ffi; sudo arch -arm64 gem install cocoapods-art
```

If you have problems with the installation, completely uninstall cocoapods and all its dependencies to perform a clean installation.

* We need to add the repository to the **netrc**file. To do so, run the following command in a Terminal:

```
$ nano ~/.netrc
```

Then copy the following snippet, replacing the placeholders with the appropriate details, to the end of the file:

```
machine facephicorp.jfrog.io
  login <USERNAME>
  password <TOKEN>
```

It is important to copy the previous code snippet **exactly** as shown. The indentation before the words **login** and **password** consists of two spaces.

* Finally, add the repository containing the private dependency:

```
pod repo-art add cocoa-pro-fphi "https://facephicorp.jfrog.io/artifactory/api/pods/cocoa-pro-fphi"
```

### Dependencies required for integration <a href="#id-22-dependencias-requeridas-para-la-integracion" id="id-22-dependencias-requeridas-para-la-integracion"></a>

To avoid conflicts and compatibility issues, if you want to install the component in a project that contains an old version of Facephi libraries (*Widgets*), they must be completely removed before installing the ***SDKMobile***.

* FacePhi libraries are currently distributed remotely through different dependency managers, in this case, ***Cocoapods***. **Required dependencies** that must be installed beforehand (by adding them to the *Podfile*):

```ruby
plugin 'cocoapods-art', :sources => [
  'cocoa-pro-fphi'
]

source 'https://cdn.cocoapods.org/'

target 'Example' do
  pod 'FPHISDKMainComponent', '~> $VERSION'

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
        config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
        config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
      end
    end
  end
end
```

* When you want to update dependencies, before running **`pod install`** use the following command to update the local repository:

```sh
pod repo-art update cocoa-pro-fphi
```

### Possible issues <a href="#id-23-posibles-incidencias" id="id-23-posibles-incidencias"></a>

If the integrator is using a MacBook with an **M1**, cocoapods-art may not install correctly. Therefore, keep the following points in mind:

* If CocoaPods was installed using Homebrew, problems may occur.
* We recommend installing CocoaPods and cocoapods-art using gem.

Below is a script that performs all the steps needed to prepare the environment so everything works correctly:

```
 #! /bin/zsh

install_cocoapods () {
    echo "Installing cocoapods with gem"
    # Creating new gems home if it doesnt't exist
    if [ ! -d "$HOME/.gem" ]; then
        mkdir "$HOME/.gem"
    fi
    # Adding to current session
    export GEM_HOME="$HOME/.gem"
    export PATH="$GEM_HOME/bin:$PATH"

    # Adding for future sessions
    if test -f "$HOME/.zshrc"; then
        echo 'Adding $GEM_HOME env var and then adding it to your $PATH'
        echo '' >> "$HOME/.zshrc"
        echo 'export GEM_HOME="$HOME/.gem"' >> "$HOME/.zshrc"
        echo 'export PATH="$GEM_HOME/bin:$PATH"' >> "$HOME/.zshrc"
        echo 'alias pod="arch -x86_64 pod"' >> "$HOME/.zshrc"
    fi

    # Installing cocoapods
    gem install cocoapods
    sudo arch -x86_64 gem install ffi
    which pod
    pod --version
    gem install cocoapods-art
}

uninstall_cocoapods_homebrew () {
    which -s brew
    if [[ $? != 0 ]] ; then
        echo "Homebrew not installed, skipping uninstalling cocoapods from homebrew"
    else
        brew uninstall cocoapods
    fi
}

if ! type "pod" > /dev/null; then
    echo "You don't have cocoapods installed..."
else
    echo "Trying to uninstall it from homebrew first"
    uninstall_cocoapods_homebrew
fi

install_cocoapods
```

If using ***xCode15*** the following configuration must be performed:

<figure><img src="https://865101184-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUo71Qbj6jZQDavjc0U5X%2Fuploads%2Fgit-blob-03c66ae3502566407290ae37eb7be78dad31ed6d%2Ffix_ldClassic-18c668c14649e02798c4250d1af70c05.png?alt=media" alt=""><figcaption></figcaption></figure>

You must add ***-ld\_classic*** in Other Linker Flags, in the app's Build Settings.

### SDK initialization <a href="#id-3-sdk-initialization" id="id-3-sdk-initialization"></a>

**You should avoid initializing a controller that will not be used.**

Each component has a controller (*Controller*) that provides access to its own functionality. Before they can be used, they must be initialized correctly. The steps for initialization are:

1. Initialize the controllers that will be used.
2. Decide whether to include the license as a `String` or through a remote licensing service (see [License injection](#id-31-inyeccion-de-licencias)) and invoke SDK initialization.
3. If initialization returns `FinishStatus.STATUS_OK`, the SDK will be ready to use.

```swift
let trackingController = TrackingController(trackingError: { trackingError in
    self.log("TRACKING ERROR: \(trackingError)")
})

// MANUAL License
SDKController.shared.initSdk(license: SdkConfigurationManager.LICENSE, output: { sdkResult in
    if sdkResult.finishStatus == .STATUS_OK {
        self.log("Manual License set successfully")
    } else {
        self.log("The manual License is incorrect")
    }
}, trackingController: trackingController)

// AUTO License
SDKController.shared.initSdk(
    licensingUrl: SdkConfigurationManager.LICENSING_URL,
    apiKey: SdkConfigurationManager.APIKEY_LICENSING,
    output: { sdkResult in
        if sdkResult.finishStatus == .STATUS_OK {
            self.log("Automatic License set successfully")
        } else {
            self.log("An error occurred while trying to obtain the license: \(sdkResult.errorType)")
        }
    },
    trackingController: trackingController)
```

#### License injection <a href="#id-31-inyeccion-de-licencias" id="id-31-inyeccion-de-licencias"></a>

As mentioned previously, there are currently two ways to inject the license:

**a. Obtaining the license through a service**

Through a service that only requires a URL and an API key as an identifier. This would avoid problems when handling the license, as well as the need to constantly replace licenses whenever an issue arises (malformation, improper modification, license expiration, etc.).

```swift
// AUTO License
SDKController.shared.initSdk(licensingUrl: SdkConfigurationManager.LICENSING_URL, apiKey: SdkConfigurationManager.APIKEY_LICENSING, output: { sdkResult in
    if sdkResult.finishStatus == .STATUS_OK {
        self.log("Automatic License set successfully")
    } else {
        self.log("An error occurred while trying to obtain the license: \(sdkResult.errorType)")
    }
}, trackingController: trackingController)
```

**b. Injecting the license as a String**

You can assign the license directly as a String, as follows:

```swift
// MANUAL License
SDKController.shared.initSdk(license: SdkConfigurationManager.LICENSE, output: { sdkResult in
    if sdkResult.finishStatus == .STATUS_OK {
        self.log("Manual License set successfully")
    } else {
        self.log("The manual License is incorrect")
    }
}, trackingController: trackingController)
```

### Start a new operation <a href="#id-4-iniciar-nueva-operacion" id="id-4-iniciar-nueva-operacion"></a>

Whenever you want to start the flow for a new operation (examples include: onboarding, Authentication, VideoCall, …), it is essential to notify the **SDKController** that it is about to begin, so the SDK knows that the subsequent calls to **Components** (also called **Steps**) will be part of that operation. This is necessary to successfully track the operation’s global information on the platform.

When starting a process or Flow, **always** you must call the method **newOperation**

This method has 3 input parameters:

1. **operationType**: Indicates whether an ONBOARDING or AUTHENTICATION process will be performed
2. **customerId**: Unique user ID, if available (managed at the application level)
3. **steps**: List of operation steps, if they have been defined beforehand

There are 2 ways to start an operation, depending on whether **the steps are known** that will make up the flow of the registration or authentication process (if the components are executed sequentially and always in the same way), or whether, conversely, the flow **is undefined** and unknown (for example, when the end customer decides the order in which the components are executed).

* Known **flow** (the tracked operation will appear on the platform with all the steps in the list). Implementation example:

```swift
SDKController.shared.newOperation(
    operationType: OperationType.X,
    customerId: "customerId",
    steps: [.SELPHI, .SELPHID, .OTHER("CUSTOM_STEP")],
    output: { _ in })
```

* Unknown **flow** (the tracked operation will appear on the platform with an ellipsis). Implementation example:

```swift
SDKController.shared.newOperation(
    operationType: OperationType.X,
    customerId: "customerId",
    output: { _ in })
```

In **`SdkResult.Success`**, the **`data`** field contains information about the created operation.

**Once the operation has been created,** the SDK components associated with this operation can be executed. See the specific documentation for each component to learn how.

#### Existing operation types <a href="#id-41-tipos-de-operacion-existentes" id="id-41-tipos-de-operacion-existentes"></a>

Currently, the following operations are available, each of which uses certain **Components (STEPS)**. The table below shows the relationship between operations and steps:

| **Operation (OperationType)** | **Component (Step)**                           | Description                                                                                                                |
| ----------------------------- | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| ONBOARDING                    | <p>SELPHI\_COMPONENT<br>SELPHID\_COMPONENT</p> | <p>- Face verification of a selfie against the face in a document<br>- Document OCR extraction<br>- Liveness detection</p> |
| AUTHENTICATION                | SELPHI\_COMPONENT                              | <p>- Facial verification using templates<br>- Liveness detection</p>                                                       |

This list will be expanded in future SDK updates as new components and use cases become available.

### Component launch options

Once the SDK has been initialized and a new operation has been created, the component can be launched. There are two ways to launch the component:

* **\[WITH TRACKING]** Launches the component and **sends events** to the *tracking*:

```swift
let controller = ExampleController(
    data: exampleConfigurationData,
    output: { sdkResult in
        // Do whatever with the result
    },
    viewController: viewController)
SDKController.shared.launch(controller: controller)
```

* **\[NO TRACKING]** Launches the component **without sending events** to the *tracking*:

```swift
let controller = ExampleController(
    data: exampleConfigurationData,
    output: { sdkResult in
        // Do whatever with the result
    },
    viewController: viewController)
SDKController.shared.launchMethod(controller: controller)
```

The **launch** method should be used **by default**. This method lets you use ***tracking*** if the component is enabled, and will not use it when it is disabled (or the component is not installed).

By contrast, the **launchMethod** method covers a special case in which the integrator has tracking installed and enabled, but does not want to track information in a particular flow within the application. In that case, this method is used to prevent that information from being sent to the platform.

### Returning a result <a href="#id-6-retorno-de-resultado" id="id-6-retorno-de-resultado"></a>

The result of each component is returned through the SDK, always using the same structure of three fields:

1. **finishStatus**: Indicates whether the operation completed successfully. Possible values: `FinishStatus.STATUS_OK`, `FinishStatus.STATUS_ERROR`
2. **errorType**: If *finishStatus* indicates that an error occurred, this field contains its description.
3. **data**: SDK response data; its structure depends on the component executed (see the documentation for each module).

### Helper methods <a href="#id-6-controladores-auxiliares" id="id-6-controladores-auxiliares"></a>

This section includes other controllers and helper operations, some of which are optional and may be needed to complete the flow correctly.

These fields are required to communicate with the **Facephi**service if you want to perform any **verification** and track a particular operation. *tracking* .

#### Getting the OperationId <a href="#id-61-obtencion-del-operationid" id="id-61-obtencion-del-operationid"></a>

```swift
SDKController.shared.getOperationId()
```

#### Getting the OperationType <a href="#id-62-obtencion-del-operationtype" id="id-62-obtencion-del-operationtype"></a>

```swift
SDKController.shared.getOperationType()
```

#### Getting the SessionId <a href="#id-63-obtencion-del-sessionid" id="id-63-obtencion-del-sessionid"></a>

```swift
SDKController.shared.getSessionId()
```

#### Getting the CustomerID <a href="#id-64-obtencion-del-customerid" id="id-64-obtencion-del-customerid"></a>

```swift
SDKController.shared.getCustomerId()
```

#### Assigning the CustomerID <a href="#id-65-asignacion-del-customerid" id="id-65-asignacion-del-customerid"></a>

```swift
SDKController.shared.setCustomerId(customerId: customerId)
```
