मुख्य सामग्री पर जाएं
iOS कैप्चर

कैप्चर को सिस्टम ब्राउज़र सेशन में खोलें और व्यक्ति को आपके ऐप में वापस लाएं।

Markdown

आपका बैक-एंड Human Plugin में Journey flow और ऐसे callbackUri के साथ process बनाता है जो आपके ऐप की URL scheme का उपयोग करता है। ऐप जवाब के link को ASWebAuthenticationSession में खोलता है। कैप्चर समाप्त होने पर, सेशन आपकी scheme के ज़रिए ऐप में लौट आता है।

create के जवाब से Human Plugin का id रखें। आपका बैक-एंड उसी से नतीजा पढ़ता है।

पूर्वापेक्षाएं​

  • iOS 13 या बाद का
  • Xcode 14 या बाद का
  • AuthenticationServices फ्रेमवर्क (अंतर्निहित)
  • आपके ऐप की अपनी यूनीक URL scheme, जैसे myapp

1. अपनी scheme के साथ process बनाएं​

आपका बैक-एंड scheme को callbackUri के रूप में भेजता है:

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

और id तथा link ऐप को लौटाता है।

2. 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. सेशन मैनेजर बनाएं​

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
}
}
जानकारी

callbackURLScheme में केवल scheme का नाम (myapp) दें, :// के बिना।

4. कैप्चर शुरू करें​

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

सारांश​

फ़ाइलउद्देश्य
CaptureContextProvider.swiftPresentation context provider
CaptureSessionManager.swiftASWebAuthenticationSession का लाइफ़साइकल