Clone this repo and change directory to example
git clone https://github.com/vouched/vouched-ios
cd vouched-ios/Example
Then, follow steps listed on the example README
- An account with Vouched
- Your Vouched Public Key
Add the package to your existing project's Podfile
pod 'Vouched', 'VOUCHED_VERSION'
This section will provide a step-by-step to understand the Vouched SDK through the Example.
Note: There are two options to run verification process flow:
- Use Camera Helper to obtain capture results. See corresponding details for VouchedCameraHelper.
- Use raw API to perform all the checks.
-
- Go through the verification process but stop after each step and take a look at the logs. Particularly understand the Job data from each step.
print(job)
- Once completed, take a look at the Job details on your Dashboard
-
Modify the SampleBufferDelegate
-
Locate the captureOutput in each Controller and make modifications.
- Add custom logic to display data or control the navigation
-
Locate the Vouched detectors and add logging
cardDetect?.detect(sampleBuffer)
barCodeDetect?.detect(sampleBuffer, cameraPosition: .back)
faceDetect?.detect(sampleBuffer)
-
-
Tweak AVCapture settings Better images lead to better results from Vouched AI
-
You are ready to integrate Vouched SDK into your app
This class is introduced to make it easier for developers to integrate VouchedSDK
and provide the optimal photography. The helper takes care of configuring the capture session, input, and output.
You can initialize the helper by specifying a Detector that you wish to use. Note how some of the controllers have a convenience method configureHelper(_ detector: Detector.Type)
to simplify the configuration of the helper.
let helper = VouchedCameraHelper(with detector: Detector.Type, helperOptions: VouchedCameraHelperOptions, detectionOptions: [VouchedDetectionOptions], in: UIView)
There are two helper methods that serve as delegates to obtain capturing results
func withCapture(delegate: @escaping ((CaptureResult) -> Void)) -> VouchedCameraHelper
Parameter Type | Nullable |
---|---|
Closure(CaptureResult ) | false |
func observeBoundingBox(observer: @escaping ((BoundingBox) -> Void)) -> VouchedCameraHelper
Parameter Type | Nullable |
---|---|
Closure(BoundingBox) | false |
In order to start capturing, put the following code:
helper.startCapture()
Once the results are ready to process/submit, stop capturing:
helper.stopCapture()
Typical usage is as following:
let helper = VouchedCameraHelper(with: .id,
detectionOptions: [.cardDetect(CardDetectOptionsBuilder().withEnableDistanceCheck(false).build())],
in: previewContainer)?
.withCapture(delegate: { (result) in
switch result {
case .empty:
...
case .id(let result):
...
default:
break
}
})
This class is introduced to help guide the ID verification modes by processing job results returned by the Vouched API service, and generating the appropriate modes that are needed to complete ID verification. This is particularly important if you are verifying identities in countries where some of the information needed for verification is on the back side of the ID, the detection manager will prompt the user to turn the card around to capture that information.
let helper: VouchedCameraHelper
let session: VouchedSession
let config = VouchedDetectionManagerConfig(session: session)
let callbacks = DetectionCallbacks
config.callbacks = callbacks
let detectionMgr = VouchedDetectionManager(helper: helper, config: config)
See CardDetectOptions for details
In order to start detection, put the following code:
detectionMgr.startDetection()
If there is a need to capture additional info the following closure will be called :
let callbacks = DetectionCallbacks { change in
let alert = UIAlertController(title: nil, message: "Turn ID card over to backside", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { _ in
change.completion(true)
})
alert.addAction(ok)
self.present(alert, animated: true)
}
Once the detection process is finished and there is a Job
result the following closure will be called:
let callbacks: DetectionCallbacks
callbacks.detectionComplete = { result in
switch result {
case .success(let job):
print("\(job)")
case .failure(let err):
print("Error: \(err)")
}
Examine the extension IdViewControllerV2 : VouchedDetectionManager
in the example app to see how this mechanism can be implemented.
This class handles a user's Vouched session. It takes care of the API calls. Use one instance for the duration of a user's verification session.
let session = VouchedSession(apiKey: "PUBLIC_KEY", groupId: "GROUP_ID")
Parameter Type | Nullable |
---|---|
String | false |
String | true |
let session = VouchedSession(apiKey: "PUBLIC_KEY", groupId: "GROUP_ID", sessionParameters: VouchedSessionParameters(token: "TOKEN"))
let job = try session.postFrontId(detectedCard: detectedCard, details: details)
Parameter Type | Nullable |
---|---|
CardDetectResult | false |
Params | true |
Returns
- Job
let job = try session.postFace(detectedFace: detectedFace)
Parameter Type | Nullable |
---|---|
FaceDetectResult | false |
Returns
- Job
let job = try session.postConfirm()
Returns
- Job
let job = try session.postReverify(jobID: String, userPhoto: String)
Returns
- Job
Parameter Type | Nullable |
---|---|
jobID | false |
userPhoto (base64 encoded string) | false |
This class handles detecting an ID (cards and passports) and performing necessary steps to ensure image is Step.postable
.
let cardDetect = CardDetect(options: CardDetectOptionsBuilder().withEnableDistanceCheck(true).build())
Parameter Type | Nullable |
---|---|
CardDetectOptions | false |
let detectedCard = cardDetect?.detect(sampleBuffer)
Parameter Type | Nullable |
---|---|
CVImageBuffer | false |
Returns
- CardDetectResult
This class handles detecting a face and performing necessary steps to ensure image is Step.postable
.
let faceDetect = FaceDetect(options: FaceDetectOptionsBuilder().withLivenessMode(.distance).build())
Parameter Type | Nullable |
---|---|
FaceDetectOptions | false |
let detectedFace = faceDetect?.detect(sampleBuffer)
Parameter Type | Nullable |
---|---|
CVImageBuffer | false |
Returns
- FaceDetectResult
The bounding box of detected ID card
for the output from Card Detection.
public struct BoundingBox {
public let box: CGRect?
public let imageSize: CGSize
}
The output from Card Detection and used to submit an ID.
struct CardDetectResult {
public let image: String?
public let distanceImage: String?
public let step: Step
public let instruction: Instruction
public let boundingBox: CGRect?
}
The output from Face Detection and used to submit a Selfie.
struct FaceDetectResult {
public let image: String?
public let distanceImage: String?
public let step: Step
public let instruction: Instruction
}
The parameters that are used to submit a Job.
struct Params: Codable{
var firstName: String?
var lastName: String?
var email: String?
var phone: String?
var birthDate: String?
var properties: [Property]?
var idPhoto: String?
var userPhoto: String?
var idDistancePhoto: String?
var userDistancePhoto: String?
}
The options for Card Detection.
class CardDetectOptionsBuilder {
public func withEnableDistanceCheck(_ enableDistanceCheck: Bool) -> CardDetectOptionsBuilder { ... }
public func withEnhanceInfoExtraction(_ enhanceInfoExtraction: Bool) -> CardDetectOptionsBuilder
public func build() -> CardDetectOptions { ... }
}
The VouchedDetectionManager can increase your verification abilities by recognizing additional sources of information based on the ID that your user submits. You can enable this behavior by using .withEnhanceInfoExtraction(true)
when setting
The options for Face Detection.
class FaceDetectOptionsBuilder {
public func withLivenessMode(_ livenessMode: LivenessMode) -> FaceDetectOptionsBuilder { ... }
public func build() -> FaceDetectOptions { ... }
}
An enum to provide an optional baseline of Verification Error(s) for a given Job.
enum RetryableError: String {
case invalidIdPhotoError
case blurryIdPhotoError
case glareIdPhotoError
case invalidUserPhotoError
}
An enum to provide mode for VouchedCameraHelper
public enum VouchedCameraMode {
case id
case barcode(String, DetectorOptions)
case selfie
}
List of options to alter image processing for VouchedCameraHelper
public struct VouchedCameraHelperOptions {
public static var usePhotoCapture: VouchedCameraHelperOptions
public static var cropIdImage: VouchedCameraHelperOptions
}
An enum to provide settings for ID
/Selfie
detection for VouchedCameraHelper
public enum VouchedDetectionOptions {
case cardDetect(CardDetectOptions)
case faceDetect(FaceDetectOptions)
}
Parameter Type | Nullable |
---|---|
CardDetectOptions | false |
FaceDetectOptions | false |
An enum to deliver detection results
public enum CaptureResult {
case empty
case id(DetectionResult)
case selfie(DetectionResult)
case barcode(DetectionResult)
}
Parameter Type | Nullable |
---|---|
DetectionResult | false |
Generic protocol, used to submit detection results
public protocol DetectionResult {
func params() throws -> Params
}
Configure VouchedLogger to the destination and level desired. If not configured, VouchedLogger defaults to .none
and .error
VouchedLogger.shared.configure(destination: .xcode, level: .debug)
Destinations - where the log output is written
- .xcode (Xcode output)
- .console (Console app via os_log)
- .none
Levels - the severity of the log
- .debug
- .info
- .error
The level is inclusive of more severe logs. i.e - .debug
will also log .info
and .error
Vouched is available under the Apache License 2.0 license. See the LICENSE file for more info.