Quick start
This guide takes you from an installed SDK to a complete verification: the user scans both sides of an identity document, takes a selfie with passive liveness, and you receive the result.
| # | Step | Call |
|---|---|---|
| 1 | Initialise | initAPI(withLicense:) |
| 2 | Start a process | startScan(for:) |
| 3 | Scan the document | detectpreviewscanDocument |
| 4 | Verify the face | validateFace(forScanId:) |
| 5 | Get the result | In your backend |
- The SDK is installed, including the face capture frameworks.
- You have a license key for your bundle ID and the URL of your MobbScan environment.
1. Initialise the SDK
Initialise once, before any other call, and set the URL of your MobbScan environment. Keep a reference to the API instance.
- Swift
- Objective-C
let mobbScan = MobbScanAPI.getInstance()
mobbScan.initAPI(withLicense: "YOUR_LICENSE_KEY") { result, validTo in
// Check the license result before continuing
}
mobbScan.baseURL = "YOUR_MOBBSCAN_URL"
self.mobbScan = [MobbScanAPI getInstance];
[self.mobbScan initAPIWithLicense:@"YOUR_LICENSE_KEY" result:^(MobbScanLicenseResult result, NSDate *validTo) {
// Check the license result before continuing
}];
self.mobbScan.baseURL = @"YOUR_MOBBSCAN_URL";
Set baseURL after initAPI. To change capture behaviour, initialise with an MSConfiguration. See Configuration.
2. Start a verification process
Each verification is a process identified by a scanId. Start one with the document type and the sides to scan:
- Swift
- Objective-C
mobbScan.startScan(for: ._ESPIDCard, for: .SCAN_BOTH_SIDES) { result, scanId, error in
// Keep scanId: every next call needs it
}
[self.mobbScan startScanForDocumentType:MobbScanDocumentType_ESPIDCard
forMode:MobbScanOperationMode_SCAN_BOTH_SIDES
withResult:^(MobbScanStartScanResult result, NSString *scanId, NSError *error) {
// Keep scanId: every next call needs it
}];
| Operation mode | Use it for |
|---|---|
SCAN_BOTH_SIDES | ID cards, residence permits and other two-sided documents |
SCAN_ONLY_BACK | One-sided documents such as passports (TD3) |
SCAN_ONLY_FRONT | Documents where only the front is required |
This example uses a two-sided identity document. For a one-sided document or passport, pass nil for the side that is not required; see Document scan.
Call startScan again for every new verification. Reusing a scanId overwrites the previous evidence.
3. Scan the document
Call detect once for each required side. The SDK presents its camera screen, detects the document automatically, dismisses the screen and returns the cropped image. Show each image in a preview that you provide; let the user accept it or repeat detection for that same side. Once every required image is accepted, send them together with one scanDocument call.
- Swift
- Objective-C
private func captureSide(_ side: MobbScanDocumentSide, onAccepted: @escaping (UIImage) -> Void) {
mobbScan.detect(side) { result, data, error in
guard result != .ERROR, error == nil, let image = data?.image else {
return self.handle(error)
}
// App-defined preview UI: accept the image or retry this same side.
self.showPreview(image) { accepted in
if accepted {
onAccepted(image)
} else {
self.captureSide(side, onAccepted: onAccepted)
}
}
}
}
captureSide(.FRONT) { frontImage in
self.frontImage = frontImage
self.captureSide(.BACK) { backImage in
self.backImage = backImage
self.scanDocument()
}
}
private func scanDocument() {
mobbScan.scanDocument(withFrontSide: frontImage, backSide: backImage, forScanId: scanId) { result, scanData, error in
result == .COMPLETED ? self.verifyFace() : self.handle(error)
}
}
- (void)captureSide:(MobbScanDocumentSide)side onAccepted:(void (^)(UIImage *))onAccepted {
[self.mobbScan detectDocumentSide:side
withDetectionResult:^(MobbScanDetectionResult result,
MobbScanDetectionResultData *data,
NSError *error) {
if (result == MobbScanDetectionResult_ERROR || error != nil || data.image == nil) {
[self handle:error];
return;
}
// App-defined preview UI: accept the image or retry this same side.
[self showPreview:data.image completion:^(BOOL accepted) {
if (accepted) {
onAccepted(data.image);
} else {
[self captureSide:side onAccepted:onAccepted];
}
}];
}];
}
[self captureSide:MobbScanDocumentSide_FRONT onAccepted:^(UIImage *frontImage) {
self.frontImage = frontImage;
[self captureSide:MobbScanDocumentSide_BACK onAccepted:^(UIImage *backImage) {
self.backImage = backImage;
[self scanDocument];
}];
}];
- (void)scanDocument {
[self.mobbScan scanDocumentWithFrontSide:self.frontImage backSide:self.backImage forScanId:scanId
andScanResult:^(MobbScanScanResult result, MobbScanScanResultData *scanData, NSError *error) {
// COMPLETED: verify the face
}];
}
Implement showPreview in your app. Retry by calling detect again for the same side; do not scan until the user accepts every required image.
For a document with a single side, pass nil as the image of the side that is not required. See Document scan for the full result reference.
4. Verify the face
Capture a selfie video with passive liveness and match it against the document portrait:
- Swift
- Objective-C
let params = MobbScanFaceValidationParams()
params.faceValidationMode = .LIVENESS_VIDEO_PASSIVE
mobbScan.validateFace(forScanId: scanId, params: params, withFaceAcquisitorResult: { result, faceData, error in
// Optional: the selfie, as soon as it is captured
}, withCheckResult: { state, validationData, error in
// state == .VALID: liveness and face match passed
})
MobbScanFaceValidationParams *params = [MobbScanFaceValidationParams new];
params.faceValidationMode = MobbScanFaceValidationMode_LIVENESS_VIDEO_PASSIVE;
[self.mobbScan validateFaceForScanId:scanId params:params
withFaceAcquisitorResult:^(MobbScanFaceAcquisitorResult result, MobbScanFaceAcquisitorData *faceData, NSError *error) {
// Optional: the selfie, as soon as it is captured
}
withCheckResult:^(MobbScanValidationState state, MobbScanValidationResultData *validationData, NSError *error) {
// VALID: liveness and face match passed
}];
5. Get the result in your backend
The callbacks are meant to drive your UI. Take the final decision in your backend, where the result cannot be tampered with: send the scanId to your server and query the process with the MobbScan Server API, or receive it through a webhook.
See Verification result for the options.