> For the complete documentation index, see [llms.txt](https://docs.recognito.vision/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.recognito.vision/face-recognition-sdk/integration-guide/ios/sample-application.md).

# Sample Application

{% embed url="<https://www.youtube.com/watch?v=9HM70PFa4lQ>" %}
NIST FRVT #1 Face Recognition, Liveness Detection Mobile SDK Demo
{% endembed %}

***

## Build Project

### - Download and Open Project

* Download [**Recognito\_Face\_iOS.zip \[21.8M\]**](https://www.dropbox.com/scl/fi/2f9kmzk4pvt1a1835c04t/Recognito_Face_iOS.zip?rlkey=xqny98ifgsgoglgwfc6edvsvb\&st=w8h1uv4b\&dl=0)
* Open the `FaceDemo` project in Xcode.

### - Setting Up SDK License Key

* Add your license to `license.txt` file:

{% code title="iOS-FaceRecognition-FaceLivenessDetection/license.txt" lineNumbers="true" %}

```
 jwIUC3mm7P9uJDPxx/gRUttdS3bDg5n3QFnyySRB/E776MSPQAMubdyFTuzFb7BCdOx4EuoHmcsO 
 rpeGfI+Z371p/7cInVsnxLZU7PcSJh45Dd7c6maTg0QPwNLDHqdyNzRLFwKXXOX/IVuQNh6Dsen1 
 mwk6RGQZfReSUU6nLvWzC5sPgYhBVemExbbIa3UdDbBC+Bm4qNeXQ2i/08s9GFrhhbuvdYyI5TGl 
 6aVFjSGoHQhm/ENI1916+ck7BiguXMA1KFRTlchSWKhyb9CllHOGTomkoBUD3ykLlMGkcuZE8wT6 
 qpaHrtnmz1TgkP3tjK7L61BaEpWNib3uH29hWA== 
```

{% endcode %}

* Build Project.

### - Integration Guide

* Activate and Initialize FaceSDK

```swift
override func viewDidLoad() {
    super.viewDidLoad()
    var ret = SDK_LICENSE_KEY_ERROR.rawValue
    if let filePath = Bundle.main.path(forResource: "license", ofType: "txt") {
        do {
            let license = try String(contentsOfFile: filePath, encoding: .utf8)
            ret = FaceSDK.setActivation(license)
        } catch {
            print("Error reading file: \(error)")
        }
    } else {
        print("File not found")
    }
    
    if(ret == SDK_SUCCESS.rawValue) {
        ret = FaceSDK.initSDK()
    }
```

* Detect Face from Camera Frame

```swift
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {    
    guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
    
    CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
    let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
    
    let context = CIContext()
    let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
    let image = UIImage(cgImage: cgImage!)
    CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)

    // Rotate and flip the image
    var capturedImage = image.rotate(radians: .pi/2)
    if(cameraLens_val == .front) {
        capturedImage = capturedImage.flipHorizontally()
    }
    
    let faceBoxes = FaceSDK.faceDetection(capturedImage)
```

* Extract Face Template

```swift
let faceBox = faceBoxes[0] as! FaceBox 
if(faceBox.liveness > livenessThreshold) {
    let templates = FaceSDK.templateExtraction(capturedImage, faceBox: faceBox)
    ...
```

* Calculate Similarity

```swift
let similarity = FaceSDK.similarityCalculation(templates, templates2: personTemplates)                    
```

***

## Application UI

<div><figure><img src="/files/gNM7fqcRqAeL7xwU0aIl" alt=""><figcaption></figcaption></figure> <figure><img src="/files/8CukMIvv7dOxOsiDjYzG" alt=""><figcaption></figcaption></figure> <figure><img src="/files/wgLcL2ti5csrbOHf5VkR" alt=""><figcaption></figcaption></figure> <figure><img src="/files/bOmqH54bNLg0Lokiltn0" alt=""><figcaption></figcaption></figure> <figure><img src="/files/XA8dMWBXwAM5aJtn6Bsp" alt=""><figcaption></figcaption></figure> <figure><img src="/files/E1qaQgqGVDLL3GQRggUu" alt=""><figcaption></figcaption></figure></div>
