# Basic SDK - iOS

## Features

* [x] Face Detection
* [x] Face Liveness Detection
* [x] Pose Estimation
* [x] Fully-Offline Works and On-Premise

## License

We offer `lifetime license(perpetual license)` tied to each  `bundle ID` for `iOS` `SDK`s.&#x20;

The license is available with a `one-time payment`—meaning once you purchase it, you can use our `SDK` indefinitely without any recurring fees.

To request a license, please contact us:

> **Email:** <contact@kby-ai.com>&#x20;
>
> **Telegram:** @kbyaisupport
>
> **WhatsApp:** +19092802609&#x20;

## System Requirements

* **CPU:** 2 cores or more
* **RAM:** 100MB or more
* **OS:** iOS 13.0 or later
* **Architecture:** arm64-v8a

## Setup

1. Copy the SDK (`facesdk.framework` folder) to the `root` folder in your project.
2. Add `SDK framework` to the project in `Xcode`.

> Project Navigator -> General -> Frameworks, Libraries, and Embedded Content

<figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2FTIjg6n66P4AlCcF79ip0%2Fimage.png?alt=media&#x26;token=46af8f4c-286e-46cf-9132-21a38eec10e2" alt=""><figcaption></figcaption></figure>

3. Add the bridging header to your `project settings`

> Project Navigator -> Build Settings -> Swift Compiler - General

<figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2FVIktW1s696XPzXEjt4b2%2Fimage.png?alt=media&#x26;token=6a1b1ed5-6da1-42d0-8efc-f3b33660145a" alt=""><figcaption></figcaption></figure>

## Initializing SDK

1. Step one

* To begin, you need to activate the SDK using the license that you have received.

```swift
FaceSDK.setActivation("...")
```

* If activation is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

2. Step Two

* After activation, call the SDK's initialization function.

```swift
FaceSDK.initSDK()
```

* If initialization is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

## Enums and Classes

### 1. SDK\_ERROR

This enumeration represents the return value of the `initSDK` and `setActivation` functions.

<table><thead><tr><th width="349.3333333333333">Feature</th><th width="99">Value</th><th>Name</th></tr></thead><tbody><tr><td>Successful activation or initialization</td><td>0</td><td>SDK_SUCCESS</td></tr><tr><td>License key error</td><td>-1</td><td>SDK_LICENSE_KEY_ERROR</td></tr><tr><td>AppID error (Not used in Server SDK)</td><td>-2</td><td>SDK_LICENSE_APPID_ERROR</td></tr><tr><td>License expiration</td><td>-3</td><td>SDK_LICENSE_EXPIRED</td></tr><tr><td>Not activated</td><td>-4</td><td>SDK_NO_ACTIVATED</td></tr><tr><td>Failed to initialize SDK</td><td>-5</td><td>SDK_INIT_ERROR</td></tr></tbody></table>

### 2. FaceBox

This class represents the output of the f`ace detection function` that contains the detected `face rectangle`, `liveness score`, and `facial angles` such as `yaw`, `roll`, and `pitch`.

| Feature                 | Type  | Name             |
| ----------------------- | ----- | ---------------- |
| Face rectangle          | int   | x1, y1, x2, y2   |
| Face angles (-45 \~ 45) | float | yaw, roll, pitch |
| Liveness score (0 \~ 1) | float | liveness         |

<div align="center"><figure><img src="https://2589216230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1WwtQK0VFwKRGmIjGA3I%2Fuploads%2Fj4XxekdSV6Q6cW9KZhPr%2Fimage.png?alt=media&#x26;token=5ace558a-3793-48f0-9324-e1ec8fe80561" alt="" width="524"><figcaption><p>Face angles</p></figcaption></figure></div>

## APIs

### 1. setActivation

To begin, you need to activate the SDK using the license that you have received.

```swift
var ret = FaceSDK.setActivation("...")
```

If activation is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

### 2. initSDK

After activation, call the SDK's initialization function.

```swift
ret = FaceSDK.initSDK()
```

If initialization is successful, the return value will be `SDK_SUCCESS`. Otherwise, an error value will be returned.

### 3. faceDetection

The SDK offers a single function for detecting face and liveness detection, which can be used as follows:

```swift
let faceBoxes = FaceSDK.faceDetection(image)
```

```swift
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 
     
    guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } 
     
    CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly) 
    let image = CIImage(cvPixelBuffer: pixelBuffer).oriented(CGImagePropertyOrientation.leftMirrored) 
    let capturedImage = UIImage(ciImage: image) 
    CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly) 
     
    let faceBoxes = FaceSDK.faceDetection(capturedImage) 
    DispatchQueue.main.sync { 
        self.faceView.setFrameSize(frameSize: capturedImage.size) 
        self.faceView.setFaceBoxes(faceBoxes: faceBoxes) 
    } 
} 
```

This function takes a single parameter, which is a `UIImage` object.&#x20;

The return value of the function is a list of FaceBox objects.&#x20;

## Default Thresholds

```swift
let livenessThreshold = 0.7
```

If the liveness score exceeds `0.7`, the face is a `real face`.&#x20;


---

# 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://docs.kby-ai.com/help/product/face-liveness-detection-sdk-face-recognition-sdk/basic-sdk-mobile/basic-sdk-ios.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.
