---
title: Pengambilan di iOS
description: Jalankan pengambilan alur Journey di aplikasi iOS dengan ASWebAuthenticationSession, menggunakan link yang dikembalikan oleh pembuatan Human Plugin.
canonical: https://developer.unico.io/id/human-plugin/integrations/ios
locale: id
generated_by: markdown-export
---

# Pengambilan di iOS

Buka pengambilan dalam sesi browser sistem dan bawa orang tersebut kembali ke aplikasi Anda.

Back-end Anda membuat proses di Human Plugin dengan alur Journey dan `callbackUri` yang menggunakan URL scheme aplikasi Anda. Aplikasi membuka `link` dari respons dalam `ASWebAuthenticationSession`. Saat pengambilan berakhir, sesi kembali ke aplikasi melalui scheme Anda.

Simpan `id` Human Plugin dari respons pembuatan. Back-end Anda membaca hasilnya dengannya.

## Prasyarat

- iOS 13 atau lebih baru
- Xcode 14 atau lebih baru
- Framework `AuthenticationServices` (bawaan)
- URL scheme yang unik untuk aplikasi Anda, seperti `myapp`

## 1. Buat proses dengan scheme Anda

Back-end Anda mengirim scheme sebagai `callbackUri`:

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

dan mengembalikan `id` serta `link` ke aplikasi.

## 2. Buat 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. Buat 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
    }
}
```

> **Informasi:** `callbackURLScheme` hanya menerima nama scheme (`myapp`), tanpa `://`.

## 4. Mulai pengambilan

```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.
    }
}
```

## Ringkasan

| File | Tujuan |
|---|---|
| `CaptureContextProvider.swift` | Presentation context provider |
| `CaptureSessionManager.swift` | Siklus hidup `ASWebAuthenticationSession` |

```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
```