API¶
This section covers the native iOS API: how to start the flow, configure the SDK, and implement the available delegates.
Delegate protocols¶
Use these protocols to receive lifecycle callbacks and events:
VideoCaptureDelegatefunc onVideoCaptureResults(results: VideoCaptureResults)func onVideoCaptureStarted()func onVideoCaptureFinished(error: VideoCaptureError?)
VideoCaptureEventsDelegatefunc onVideoCaptureEvent(event: VideoCaptureEvent)
Starting a flow¶
1) Create a VideoCaptureConfiguration (build it in code or decode from JSON).
2) Set the events delegate (optional but recommended).
3) Start the SDK with your delegate and configuration.
import UIKit
import VeridasSelfieSDK
final class MyController: UIViewController, VideoCaptureDelegate, VideoCaptureEventsDelegate {
func startVideoSelfie() {
let config = loadConfigFromJSON("videoSelfie", as: VideoCaptureConfiguration.self)
VideoCapture.setEventsDelegate(delegate: self) // VideoCaptureEventsDelegate
VideoCapture.start(delegate: self, configuration: config) // VideoCaptureDelegate
}
// VideoCaptureDelegate
func onVideoCaptureResults(results: VideoCaptureResults) { print(results) }
func onVideoCaptureStarted() { print("SDK started") }
func onVideoCaptureFinished(error: VideoCaptureError?) { print(error as Any) }
// VideoCaptureEventsDelegate
func onVideoCaptureEvent(event: VideoCaptureEvent) { print(event) }
}
Example helper for loading JSON configs (shared by all SDKs):
private func loadConfigFromJSON<T: Decodable>(_ name: String, as type: T.Type) -> T {
guard let url = Bundle.main.url(forResource: name, withExtension: "json") else {
fatalError("Missing \(name).json in app bundle")
}
do {
let data = try Data(contentsOf: url)
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Failed decoding \(name).json: \(error)")
}
}
ViewModel example¶
import Foundation
import Combine
import VeridasCommonDefinitions
import VeridasSelfieSDK
final class MainSdkViewModel: ObservableObject {
func startVideoSelfie() {
let config = loadConfigFromJSON("videoSelfie", as: VideoCaptureConfiguration.self)
VideoCapture.setEventsDelegate(delegate: self)
VideoCapture.start(delegate: self, configuration: config)
}
private func loadConfigFromJSON<T: Decodable>(_ name: String, as type: T.Type) -> T {
guard let url = Bundle.main.url(forResource: name, withExtension: "json") else {
fatalError("Missing \(name).json in app bundle")
}
do {
let data = try Data(contentsOf: url)
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Failed decoding \(name).json: \(error)")
}
}
}
extension MainSdkViewModel: VideoCaptureDelegate, VideoCaptureEventsDelegate {
func onVideoCaptureResults(results: VideoCaptureResults) { print("onVideoCaptureResults \(result)") }
func onVideoCaptureStarted() { print("onVideoCaptureStarted") }
func onVideoCaptureEvent(event: VideoCaptureEvent) { print("onVideoCaptureEvent \(event)") }
func onVideoCaptureFinished(error: VideoCaptureError?) { print("onVideoCaptureFinished \(String(describing: error))") }
}
Dispatched events¶
The SDK dispatches a set of events to communicate that the corresponding actions have been taken. Each event is sent to onVideoCaptureEvent(event:), which receives a Codable object:
public struct VideoCaptureEvent: Codable, CustomStringConvertible
This object contains 2 main attributes, type with the event identifier and detail with all the information related to the event.
| Event Name | Event Detail | Event Trigger |
|---|---|---|
| VD_instructions | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When initial instructions are displayed. |
| VD_mounted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the SDK is mounted. |
| VD_unmounted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the SDK is unmounted. |
| VD_loaded | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the SDK is fully loaded. |
| VD_cameraPermissionsGranted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the user grants camera permissions. |
| VD_cameraStarted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the camera starts successfully. |
| VD_cameraVideoPlayStarted | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the camera video playback begins. |
| VD_cameraRecorderSetup | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" "width": 1920, "height": 1080 |
When the camera recording is configured. |
| VD_capturedSelfie | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When face detection is completed. |
| VD_capturedObverse | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the front side of the document is captured. |
| VD_cameraRecorderStop | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the camera recording is stopped. |
| VD_capturedReverse | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the back side of the document is captured. |
| VD_successTickFinish | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the success tick animation finishes. |
| VD_capture | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the video capture is complete. |
| VD_processFinished | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the whole process is finished, either successfully or with an error. |
| VD_cameraFailureDefaultError | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When camera can't be initialised for any reason. |
| VD_cameraFailurePermissionError | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When camera permissions are denied. |
| VD_closeClicked | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the close button is clicked and user exits from confirmation modal. |
| VD_restartProcess | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When the process needs to be restarted due to an error. |
| VD_restartFromModal | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the process needs to be restarted after help modal. |
| VD_restartClicked | "sdkName": "VD-VIDEO", "type": "info", "flowType": "video" |
When the restart button is clicked after feedback screen. |
| VD_detectionTimeout | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When the flow ends due to timeout. |
| VD_loseFocus | "sdkName": "VD-VIDEO", "type": "error", "flowType": "video" |
When the user has lost the focus on the browser tab. |