Document Verification is exposed as a flow which performs the following high level steps:
Displays instructions to the user
Requests camera permissions (if not already granted)
Performs Document Capture
Performs Selfie Capture
Submits the job to the Smile ID API
Delivers the result back to the caller
import android.util.Logimport androidx.compose.runtime.Composableimport com.smileidentity.SmileIDimport com.smileidentity.compose.SmartSelfieRegistrationimport com.smileidentity.results.SmartSelfieResult@ComposablefunDocumentVerificationExample() {// It will need to be provided as input depending on your use case SmileID.DocumentVerification(country ="GH") { result ->when (result) {is SmileIDResult.Success -> {val resultData = result.data Log.d("DocumentVerification", "Success: $resultData")// DocumentVerificationResult contains: captured documents, captured selfie,// and job status response from the APIval (selfieFile, documentFrontFile, documentBackFile, jobStatusResponse) = resultData }is SmileIDResult.Error -> {// There was an error (could be denied camera permissions, network errors, etc)val throwable = result.throwable Log.w("DocumentVerification", "Failure: $it", throwable) } } }}
let documentVerificationScreen = SmileID.documentVerificationScreen(...)let controller =UIHostingController(rootView: documentVerificationScreen)controller.modalPresentationStyle = .fullScreennavigationController?.present(controller, animated:true)
SmileIDDocumentVerification( countryCode:"GH",// There are more parameters -- they correspond 1:1 with the native SDK parameters onSuccess: (String? result) {// Your success handling logic }, onError: (String errorMessage) {// Your error handling logic })
On success, you will receive a JSON string following the structure:
⚠️Note: Recommend wrapping this in a component that can be navigated to and out of view due to a known issue with views displaying dialogs particularly on failure and the dialog keeps showing,
<SmileIDDocumentVerificationView allowAgentMode:false,// true if you need to use the secondary camera showInstructions:true,// show instructions before capture countryCode:'<country code>', documentType:'<document type>', captureBothSides:true,// true if capturing back and front of document allowGalleryUpload:false,//true if document can be uploaded from gallery onResult={(event) => {setResult(event.nativeEvent.result); }}/>
On onResult, you will receive a JSON string following the structure:
{"selfieFile":"<path to selfie file>","livenessFiles":"<path to liveness file>","documentFrontFile":"<path to document front file>","documentBackFile":"<path to document back file>","apiResponse": {"code":"...","created_at":true | false,"job_id":true | false,"job_type":"","message":"","partner_id":"","partner_params":"","status":"","updated_at":"","user_id":"", }}
Arguments
country
A 2-letter country code (ISO 3166-1 alpha-2 compliant)
documentType
The type of document/ID that is to be captured. If omitted, the document type will be automatically determined
captureBothSides
Boolean indicating whether both sides of the ID card should be captured. When set to true, the user will still be presented with the option to skip capturing the back of the ID card. This value can be fetched by calling SmileID.api.getValidDocuments() and checking the hasBack property of a document
bypassSelfieCaptureWithFile
If this value is provided, then the user will not be asked to capture a selfie as part of this flow
userId
The user ID to associate with the job. Most often, this will correspond to a unique User ID within your own system. (If not provided at time of Registration, a random user ID will be generated. This field is required for Authentication)
jobId
The job ID to associate with the job. Most often, this will correspond to a unique Job ID within your own system. If not provided, a random job ID will be generated.
idAspectRatio
The aspect ratio of the ID to be captured. If not specified, the aspect ratio will attempt to be inferred from the device's camera.
showAttribution
Whether to show the Smile ID attribution or not on the Instructions screen
allowGalleryUpload
Whether the user should be allowed to upload their document photos from the Gallery instead of performing a live capture
showInstructions
Whether to deactivate capture screen's instructions
extraPartnerParams
Custom values specific to partners passed as an immutable map
Callback to be invoked when the job is complete. The result itself is a SmileIDResult which can either be a SmileIDResult.Success or SmileIDResult.Error
delegate (iOS)
This is the delegate object that is notified when there is a result from the DocumentVerification flow. This class has to conform to DocumentCaptureResultDelegate and implement the delegate methods
func didSucceed(selfie: URL, documentFrontImage: URL, documentBackImage: URL?, jobStatusResponse: DocumentVerificationJobStatusResponse) and func didError(error: Error).