# Youverify Liveness iOS SDK

[Get your Public Merchant Key](/getting-started/getting-your-public-merchant-key.md)

### Installation

The Installation Step should be:&#x20;

For iOS 13 and later:

```
pod 'YouverifyLivenessSDK'
```

For iOS 12 and earlier:

```
pod 'YouverifyLivenessSDKCompat'
```

Example Podfile for iOS 12 and earlier:

```
platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
  pod 'YouverifyLivenessSDK'  # Use this for iOS 13+
  # pod 'YouverifyLivenessSDKCompat'  # Uncomment this for iOS 12 and below
end
```

After saving the changes to your `Podfile`, run the following command in Terminal:`pod install`

### Usage

1. Import the package into your web page like so:

```swift
import YVLivenessSDK
```

2. Initialize an instance of the package, like so:

```swift
@StateObject var yvLiveness: IosSDK

_yvLiveness = StateObject(wrappedValue: IosSDK(options))
```

For a list of the valid options, check this out

3. Start the process, like so:

```swift
yvLiveness.startSDK();
```

This could also be called with an array of tasks. The supplied tasks override those provided during initialization.

```swift
let livenessTasks = [
    TaskProperties(task: 
        YVTask.completeTheCircle(CompleteTheCircleTask(difficulty: .medium))
    )
]

yvLiveness.startSDK(tasks: livenessTasks)
```

4. Add the SDKView to your page, and the controls for the modal as so:

```swift
if iosSDK.isDialogVisible {
    SDKView(
        sdk: iosSDK
    )
}
```

Full Example:

```swift
@StateObject var iosSDK: IosSDK

init() {
    _iosSDK = StateObject(wrappedValue: IosSDK(
        publicKey: "PUBLIC_KEY",
        user: SDKUser,
        onSuccess: {data in
            print("The data returned is \(data)")
        }
    ))
}

Button(action: {
    iosSDK.startSDK(tasks: [
        TaskProperties(task: 
            YVTask.completeTheCircle(CompleteTheCircleTask(difficulty: .medium))
        )
    ])
}) {
    Text("Complete the Circle")
}

if iosSDK.isDialogVisible {
    SDKView(
        sdk: iosSDK
    )
}
```

Options

<table><thead><tr><th width="109">Option</th><th width="131.48565673828125">Type</th><th width="63">Required</th><th width="194.3333740234375">Description</th><th width="67">Default Value	</th><th>Possible Values</th></tr></thead><tbody><tr><td><strong>sandboxEnvironment</strong></td><td>Boolean</td><td>No</td><td>Sets whether session should run in sandbox or live mode</td><td><strong>true</strong></td><td><strong>true, false</strong><br></td></tr><tr><td><strong>tasks</strong></td><td>Array</td><td>No</td><td>NoSets tasks that need to be performed for liveness to be confirmed</td><td>nil</td><td><br></td></tr><tr><td><strong>user</strong></td><td>Class</td><td>Yes</td><td>Sets details of user for which liveness check is being performed</td><td>-</td><td>Any string<br></td></tr><tr><td><strong>user.firstName</strong><br></td><td>String</td><td>Yes</td><td>First name of user</td><td>-</td><td>Any string</td></tr><tr><td><strong>user.lastName</strong><br></td><td>String</td><td>No</td><td>Last name of user</td><td>nil</td><td>Any string</td></tr><tr><td><strong>user.email</strong></td><td>String</td><td>No</td><td>Email of user</td><td>nil</td><td>Any string</td></tr><tr><td><strong>onClose</strong></td><td>Function</td><td>No</td><td>Callback function that gets triggered when modal is closed</td><td>nil</td><td>Any valid function</td></tr><tr><td><strong>onSuccess</strong></td><td>Function</td><td>No</td><td>Callback function that gets triggered when all tasks have been completed and passed. Called with completion <a href="https://markdownlivepreview.com/#liveness-data">data</a></td><td>nil</td><td>Any valid function</td></tr><tr><td><strong>onFailure</strong></td><td>Function</td><td>No</td><td><br></td><td>nil</td><td>Any valid function</td></tr></tbody></table>

### Tasks

A task is a series of instructions for users to follow to confirm liveness. Find below a list of tasks.

> PS: We aim to frequently add to this list a variety of fun and yet intuitive ways of confirming liveness, so be on the lookout for more tasks!

They are:

#### Complete The Circle

User passes task by completing imaginary circle with head movement.

**CompleteTheCircleTask option**

| Option         | Type           | Required | Description                                                    | Default Value | Possible Values             |
| -------------- | -------------- | -------- | -------------------------------------------------------------- | ------------- | --------------------------- |
| **difficulty** | TaskDifficulty | No       | Sets difficulty of task                                        | **.medium**   | `.easy`, `.medium`, `.hard` |
| **timeout**    | Number         | No       | Sets time in milliseconds after which task automatically fails | nil           | Any number in milliseconds  |

#### Yes Or No

User passes task by answering a list of arbitrary questions set by you with the tilting of the head; right for a `yes` and left for a `no`.

**YesOrNoTask option**

<table><thead><tr><th>Option</th><th>Type</th><th width="93.33331298828125">Required</th><th>Description</th><th>Default Value	</th><th>Possible Values difficulty</th></tr></thead><tbody><tr><td><strong>difficulty</strong></td><td>TaskDifficulty</td><td>No</td><td>Sets difficulty of task</td><td><strong>.medium</strong></td><td><code>.easy</code>, <code>.medium</code>, <code>.hard</code></td></tr><tr><td><strong>timeout</strong></td><td>Number</td><td>No</td><td>Sets time in milliseconds after which task automatically fails</td><td>nil</td><td>Any number in milliseconds</td></tr><tr><td><strong>questions</strong></td><td>Array</td><td>No</td><td>A set of questions to ask user</td><td>nil</td><td>See nested options below</td></tr><tr><td><strong>questions.question</strong></td><td>String</td><td>Yes</td><td>Question to ask user. Should be a <code>true</code> or <code>false</code> type question. Eg: "Are you ready"</td><td>-</td><td>Any string</td></tr><tr><td><strong>questions.answer</strong></td><td>Bool</td><td>Yes</td><td>Answer to the question</td><td>-</td><td><code>true</code>, <code>false</code></td></tr><tr><td><strong>questions.errorMessage</strong></td><td>String</td><td>No</td><td>Error message to display if user gets question wrong</td><td>undefined</td><td>Any string</td></tr></tbody></table>

#### Motions

User passes task by performing random motions in random sequences, which include `nodding`, `blinking` and `opening of mouth`.

**MotionsTaskClass option**

| Option           | Type           | Required | Description                                                    | Default Value | Possible Values             |
| ---------------- | -------------- | -------- | -------------------------------------------------------------- | ------------- | --------------------------- |
| **`difficulty`** | TaskDifficulty | No       | Sets difficulty of task                                        | .medium       | `.easy`, `.medium`, `.hard` |
| **`timeout`**    | TimeInterval   | No       | Sets time in milliseconds after which task automatically fails | nil           | Any number in milliseconds  |
| **`maxNods`**    | Int            | No       | Maximum amount of nods a user is asked to perform              | 5             | Any number                  |
| **`maxBlinks`**  | Int            | No       | Maximum amount of nods a user is asked to perform              | 5             | Any number                  |

#### TaskProperties

User passes in the class and preferred settings for each task.

| Option      | Type         | Required | Description                                                    | Default Value | Possible Values                                                  |
| ----------- | ------------ | -------- | -------------------------------------------------------------- | ------------- | ---------------------------------------------------------------- |
| **task**    | YVTask       | Yes      | Id of task                                                     | -             | `YVTask.completeTheCircle(Task_class eg. CompleteTheCircleTask)` |
| **timeout** | TimeInterval | No       | Sets time in milliseconds after which task automatically fails | nil           | Any number in milliseconds                                       |

### Liveness Data

The `onSuccess` and `onFailure` callbacks (if supplied) are passed the following data:

| Option                | Type   | Description                                          |
| --------------------- | ------ | ---------------------------------------------------- |
| **data**              | Object | Data passed through callback                         |
| **data.faceImage**    | String | Face Image of user performing liveness check         |
| **data.livenessClip** | String | Video of user performing liveness check              |
| **data.passed**       | Bool   | Indicator on whether liveness check passed or failed |
| **data.metadata**     | Any    | Metadata passed in during initialization             |

### Credits

This SDK is developed and maintained solely by [Youverify](https://youverify.co)


---

# Agent Instructions: 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:

```
GET https://doc.youverify.co/know-your-customer-services-kyc/sdk/ios-sdk/youverify-liveness-ios-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
