iOS 캡처
시스템 브라우저 세션에서 캡처를 열고 사용자를 앱으로 돌려보냅니다.
백엔드가 Journey 플로우와 앱의 URL 스킴을 사용하는 callbackUri로 Human Plugin에서 프로세스를 생성합니다. 앱은 응답의 link를 ASWebAuthenticationSession에서 엽니다. 캡처가 끝나면 세션이 사용자의 스킴을 통해 앱으로 돌아옵니다.
생성 응답의 Human Plugin id를 보관하세요. 백엔드가 이 값으로 결과를 읽습니다.
사전 요구 사항
- iOS 13 이상
- Xcode 14 이상
AuthenticationServices프레임워크(기본 내장)- 앱 고유의 URL 스킴(예:
myapp)
1. 스킴을 지정해 프로세스 생성
백엔드가 스킴을 callbackUri로 전송합니다.
{
"flow": "humantoken",
"clientId": "client-a",
"correlationId": "order-1001",
"credential": { "type": "DUI_TYPE_NG_BVN", "value": "<document number>" },
"callbackUri": "myapp://callback"
}
그리고 id와 link를 앱에 반환합니다.
2. 프레젠테이션 컨텍스트 제공자 생성
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. 세션 매니저 생성
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. 캡처 시작
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 수명 주기 |