---
title: iOS 캡처
description: Human Plugin 생성 응답이 반환한 링크를 사용해 iOS 앱에서 ASWebAuthenticationSession으로 Journey 플로우의 캡처를 실행합니다.
canonical: https://developer.unico.io/ko/human-plugin/integrations/ios
locale: ko
generated_by: markdown-export
---

# iOS 캡처

시스템 브라우저 세션에서 캡처를 열고 사용자를 앱으로 돌려보냅니다.

백엔드가 Journey 플로우와 앱의 URL 스킴을 사용하는 `callbackUri`로 Human Plugin에서 프로세스를 생성합니다. 앱은 응답의 `link`를 `ASWebAuthenticationSession`에서 엽니다. 캡처가 끝나면 세션이 사용자의 스킴을 통해 앱으로 돌아옵니다.

생성 응답의 Human Plugin `id`를 보관하세요. 백엔드가 이 값으로 결과를 읽습니다.

## 사전 요구 사항

- iOS 13 이상
- Xcode 14 이상
- `AuthenticationServices` 프레임워크(기본 내장)
- 앱 고유의 URL 스킴(예: `myapp`)

## 1. 스킴을 지정해 프로세스 생성

백엔드가 스킴을 `callbackUri`로 전송합니다.

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

그리고 `id`와 `link`를 앱에 반환합니다.

## 2. 프레젠테이션 컨텍스트 제공자 생성

```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. 세션 매니저 생성

```swift
import AuthenticationServices

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

    /// 캡처가 끝나면 true, 사용자가 닫으면 false로 completion을 호출합니다.
    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
    }
}
```

> **정보:** `callbackURLScheme`에는 `://` 없이 스킴 이름(`myapp`)만 입력합니다.

## 4. 캡처 시작

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

CaptureSessionManager.shared.start(link: url) { ended in
    if ended {
        // 캡처가 끝났습니다. 백엔드에 Human Plugin id로
        // GET /v1/processes/{id}를 호출해 결과를 읽도록 요청하세요.
    } else {
        // 사용자가 세션을 닫았습니다.
    }
}
```

## 요약

| 파일 | 용도 |
|---|---|
| `CaptureContextProvider.swift` | 프레젠테이션 컨텍스트 제공자 |
| `CaptureSessionManager.swift` | `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
```