Skip to main content

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.

#StepCall
1InitialiseinitAPI(withLicense:)
2Start a processstartScan(for:)
3Scan the documentdetectpreviewscanDocument
4Verify the facevalidateFace(forScanId:)
5Get the resultIn your backend
Before you begin
  • 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.

let mobbScan = MobbScanAPI.getInstance()

mobbScan.initAPI(withLicense: "YOUR_LICENSE_KEY") { result, validTo in
// Check the license result before continuing
}
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:

mobbScan.startScan(for: ._ESPIDCard, for: .SCAN_BOTH_SIDES) { result, scanId, error in
// Keep scanId: every next call needs it
}
Operation modeUse it for
SCAN_BOTH_SIDESID cards, residence permits and other two-sided documents
SCAN_ONLY_BACKOne-sided documents such as passports (TD3)
SCAN_ONLY_FRONTDocuments 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.

One process per verification

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.

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

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:

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

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.

Next steps​