Usage (Swift)
Under Development: This SDK is currently in development. Documentation and API may change. For production use, please contact our team.
Overview
The vouch iOS SDK provides a SwiftUI-based interface for initiating and managing verification flows within your iOS application. The SDK handles the entire verification process, from user interaction to proof generation, while maintaining your application's context and user experience.
Initialization
The SDK instance should be initialized at the application level and kept alive for the duration of your app's lifecycle. This ensures proper state management and allows multiple verification requests throughout the user's session.
Recommended initialization pattern:
import SwiftUI
import VouchSDK
@main
struct SDKDemoApp: App {
let sdk = VouchSDK.SDK(customerId: "CUSTOMER_ID")
var body: some Scene {
WindowGroup {
ContentView(sdk: sdk)
}
}
}Important: Keep the SDK instance alive for the entire lifecycle of your application. Creating multiple instances may lead to unexpected behavior.
Requesting a Verification
To initiate a verification flow, call the start method on your SDK instance. This method returns a SwiftUI view that can be embedded directly into your application's UI, such as in a popover, sheet, or navigation stack.
Basic usage example:
yourView
.popover(isPresented: $popoverVisible) {
sdk.start(
dataSourceId: "DATA_SOURCE_ID",
webhookUrl: "WEBHOOK_URL",
inputs: [
"INPUT1_NAME": "INPUT1_VALUE",
"INPUT2_NAME": "INPUT2_VALUE",
"INPUT3_NAME": "INPUT3_VALUE"
],
callback: { result in
switch result {
case .success(let success):
print("Proof id: \(success.proofId)")
case .failure(let error):
print("Proof with id failed: \(error.proofId), reason: \(error.reason)")
}
popoverVisible = false
}
)
}Parameters
Initializing the SDK requires your customerId.
The start method accepts the following parameters. For detailed documentation on dataSourceId, webhookUrl, and inputs, see the Vouch URL Parameters section.
Note: In the iOS SDK, inputs is passed as a [String: String] dictionary rather than a base64-encoded JSON string. The SDK handles serialization and encoding internally.
callback
Type: (Result<Success, Failure>) -> Void
A closure that is called when the verification process completes, either successfully or with an error. Both success and failure cases provide a proofId that can be used to track the verification request.
Success case:
- Contains
proofId: The unique identifier of the generated proof
Failure case:
- Contains
proofId: The unique identifier of the failed proof request - Contains
reason: AFailureReasonenum value describing why the verification failed
Error Handling
The SDK provides comprehensive error handling through the callback closure. All failure cases include both a proofId and a specific reason to help diagnose issues.
Failure Reasons
The following failure reasons may be returned in the callback:
| Reason | Description |
|---|---|
dataSourceOrCustomerNotFound | The provided dataSourceId or customerId does not match any known entity in the vouch system. Verify your IDs are correct. |
outdatedVersion | A newer version of the SDK is available and must be downloaded. Update the SDK to the latest version. |
creatingProofRequestFailed | The SDK was unable to create the proof request. This may indicate a network or configuration issue. |
backgroundTimeout | The user kept the application in the background for too long during verification. The app must remain active for the entire verification process. |
requestTooLarge | The captured request exceeds size limits and cannot be notarized. Consider using a different data source or reducing the scope of verification. |
dataSourceMisconfigured | The selected data source contains unsupported configuration. Contact support or try a different data source. |
provingFailed | The SDK failed to notarize the request. This may indicate a technical issue with the verification process. |
proofUploadFailed | The SDK failed to upload the proof to the vouch server. Check network connectivity and retry. |
attachmentReuploadFailed | The SDK failed to upload attachments to your server. Verify your webhook endpoint is accessible and properly configured. |
proofIdTaken | A proof with the same ID already exists on the vouch server. Ensure proof IDs are unique. |
networkConnectionLost | The device lost internet connection during verification. Ensure stable connectivity and retry. |
Best Practice: Always handle both success and failure cases in your callback. Log the proofId for debugging and user support purposes.
Version checking (iOS 14-16.3)
VouchSDK functionalities are disabled on iOS 14-16.3. To check if your current iOS version is supported:
if (VouchSDK.isSupported) {
... // Initialize and start
} else {
... // Show an error
}