Skip to main content
iOS capture

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

Markdown

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:

{
"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​

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​

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​

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​

FilePurpose
CaptureContextProvider.swiftPresentation context provider
CaptureSessionManager.swiftASWebAuthenticationSession lifecycle