# Face capture and liveness

Run a live selfie workflow and optionally compare it with the NFC portrait.

## What users see

Face capture returns a selfie JPEG when available and separate liveness outcomes. Comparing the selfie with a passport chip portrait is a separate call that can return a similarity score.

Illustrative screens with a fictional demo subject.

![Illustrated iPhone screen guiding a fictional subject through a liveness capture](/assets/modules/face-capture.jpg)
Follow the selfie prompts

![Illustrated result showing a selfie alongside a passport portrait](/assets/modules/face-results.jpg)
Review a face comparison

## Present the selfie flow

Enable camera permission and present this view. A nil result indicates cancellation. A capture result can report challenge progress without returning a JPEG.

```swift
Identomic.face(checksPassiveLiveness: true) { face in
    guard let face else { return }
    guard face.activeLivenessPassed, let jpeg = face.jpeg else {
        // Offer retry or return to your app's capture screen.
        return
    }
    // Use jpeg and inspect face.passiveLivenessPassed separately.
}
```

## Read the outcome

FaceCapture includes jpeg, completedChallenges, activeLivenessPassed and optional passiveLivenessPassed. Treat a missing passive result as unavailable and handle it according to your app’s policy.

## Handle each outcome

- On cancellation, dismiss the capture flow.
- If the JPEG is missing or active liveness failed, allow retry or return to the previous step.
- Handle passive liveness independently. When a result is missing, use the unavailable state defined by your workflow.

## Compare with the chip portrait

Use a completed FaceCapture and a PassportChip. The result exposes similarityPercent, meetsMatchThreshold, and failure. The score is a model similarity value, and the comparison can be inconclusive.

```swift
let comparison = await Identomic.compareFace(faceCapture, with: passportChip)
if let score = comparison.similarityPercent {
    // Read score and comparison.meetsMatchThreshold.
} else {
    // Handle comparison.failure and offer a retry when appropriate.
}
```
