---
title: iOS capture
description: Run the capture of a Journey flow in an iOS app with ASWebAuthenticationSession, using the link returned by the Human Plugin create.
canonical: https://developer.unico.io/human-plugin/integrations/ios
locale: en
generated_by: markdown-export
---

# iOS capture

Open the capture in a system browser session and bring the person back to your app.

Your back-end creates the process in Human Plugin with a Journey flow and a `callbackUri` that uses your app's URL scheme. The app opens the `link` from the response in an `ASWebAuthenticationSession`. When the capture ends, the session returns to the app through your scheme.

Keep the Human Plugin `id` from the create response. Your back-end reads the outcome with it.

## Prerequisites

- iOS 13 or later
- Xcode 14 or later
- The `AuthenticationServices` framework (built in)
- A URL scheme unique to your app, such as `myapp`

## 1. Create the process with your scheme

Your back-end sends the scheme as `callbackUri`:

```json
{
  "flow": "humantoken",
  "clientId": "client-a",
  "correlationId": "order-1001",
  "credential": { "type": "DUI_TYPE_NG_BVN", "value": "<document number>" },
  "callbackUri": "myapp://callback"
}
```

and returns `id` and `link` to the app.

## 2. Create the presentation context provider

```swift
import AuthenticationServices
import UIKit

class CaptureContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding {
    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
              let window = windowScene.windows.first else {
            return ASPresentationAnchor()
        }
        return window
    }
}
```

## 3. Create the session manager

```swift
import AuthenticationServices

class CaptureSessionManager {
    static let shared = CaptureSessionManager()
    private var session: ASWebAuthenticationSession?
    private let contextProvider = CaptureContextProvider()

    /// Calls completion with true when the capture ended, false when the person closed it.
    func start(link: URL, completion: @escaping (Bool) -> Void) {
        let newSession = ASWebAuthenticationSession(
            url: link,
            callbackURLScheme: "myapp"
        ) { callbackURL, _ in
            self.session = nil
            completion(callbackURL != nil)
        }
        newSession.presentationContextProvider = contextProvider
        newSession.prefersEphemeralWebBrowserSession = true
        newSession.start()
        session = newSession
    }
}
```

> **Info:** `callbackURLScheme` takes only the scheme name (`myapp`), without `://`.

## 4. Start the capture

```swift
guard let url = URL(string: link) else { return }

CaptureSessionManager.shared.start(link: url) { ended in
    if ended {
        // The capture ended. Ask your back-end to read the outcome
        // with GET /v1/processes/{id}, using the Human Plugin id.
    } else {
        // The person closed the session.
    }
}
```

## Summary

| File | Purpose |
|---|---|
| `CaptureContextProvider.swift` | Presentation context provider |
| `CaptureSessionManager.swift` | `ASWebAuthenticationSession` lifecycle |

```mermaid
sequenceDiagram
  participant A as Your app
  participant B as Your back-end
  participant H as Human Plugin
  participant S as Browser session
  A->>B: start the capture
  B->>H: POST /v1/processes (Journey flow, callbackUri myapp://callback)
  H-->>B: 201, id + link
  B-->>A: id + link
  A->>S: open link
  Note over S: capture
  S-->>A: myapp://callback
  A->>B: capture ended (id)
  B->>H: GET /v1/processes/{id}
  H-->>B: 200, final state
```