Core
Introduction
The Core
module is the main component of Verifai.
Everything that is needed to scan documents and communicate with our backend services,
is available in the Core module.
Use the Core module when you would like to quickly read and process the information on a user's identity document.
If you also want to verify the document itself for validity, then the NFC
module is the best option.
The NFC module will automatically handle a Core scan that facilitates its scanning flow.
Example
Verifai can be configured and started with just a few lines of code. The code example below shows how to quickly run the SDK in its default configuration:
do {
try Verifai.start(over: self) { result in
switch result {
case .failure(let error):
print("Error or cancellation: \(error)")
case .success(let successResult):
// Continue with the result
let mrzData = successResult.mrzData
// Print the given names
print("Given names: \(mrzData?.givenNames)")
}
}
} catch {
print("🚫 Unhandled error: \(error)")
}
do {
let result = try await Verifai.start(over: self)
// Continue with the result
let mrzData = result.mrzData
// Print the given names
print("Given names: \(mrzData?.givenNames)")
} catch {
print("🚫 Error or cancellation: \(error)")
}
The result received immediately has some information from the document. This info can be used for displaying purposes. For the verified information will be available through webhooks in your backend.
Configuration
Options
The Core module has the following configuration options:
Setting | Description | Adds validator | Default |
---|---|---|---|
enableCropping | Controls the cropping interaction | - | true |
enableManualFlow | Controls if you can manually draw masking | - | true |
requireDocumentCopy | If false , you won't go to automatic mode and correction screens | - | true |
requireCroppedImage | If false , you will receive a full image taken and not only the document | - | true |
requireMrz | If true , it adds a validator and disables all docs without MRZ | HasMrz | false |
requireNFCWhenAvailable | Adds an NFC key validator if the document has an NFC chip | NfcKeyWhenAvailable | false |
enableVisualInspection | Whether the Visual inspection zone on the document should be OCR'ed | - | false |
Extra configuration options:
Configuration option | Description | Default value |
---|---|---|
validators | Array of validators that will be run after the automatic or manual scans | empty VerifaiValidator array |
documentFilters | Array of document filters that determine which documents a user can select in the manual flow | empty VerifaiDocumentFilter array |
autoCreateValidators | Whether setting document filters automatically creates validators for the automatic scan views | true |
customDismissButtonTitle | Dismiss button string value | nil |
instructionScreenConfiguration | How the instruction screens are setup in the SDK. Including the ability to hide / customize individual ones with custom text or an URL | All instruction screens are shown in default mode |
scanHelpConfiguration (iOS) | How the scan help throughout the flow should be configured | Default VerifaiScanHelpConfiguration settings. |
Note on the Dismiss button
On iOS it's also possible to configure the dismiss bar button item title for the modally presented Verifai view.
To do this set the value of customDismissButtonTitle
inside the VerifaiCoreConfiguration
.
It is your responsibility to provide the string with the right translation.
If no string is provided then Verifai will default to using Cancel
.
In that case, when no string is provided, Verifai will also take care of translating the default string.
Example
In order to set a custom configuration for Verifai
you have to supply a VerifaiCoreConfiguration
.
This configuration can then be set using Verifai.configure(with:)
,
during which the configuration will be checked for errors.
let config = VerifaiCoreConfiguration(requireDocumentCopy: true,
requireCroppedImage: true,
requireNFCWhenAvailable: true)
// Extra configuration
// Instruction screens (optional)
let instructionScreenConfiguration =
try VerifaiInstructionScreenConfiguration(instructionScreens: [
.documentPickerInstruction: .defaultScreen,
.mrzPresentFlowInstruction: .hidden
])
config.instructionScreenConfiguration = instructionScreenConfiguration
do {
try Verifai.configure(with: config)
} catch VerifaiConfigurationError.invalidConfiguration(let description) {
print("🚫 Invalid configuration: " + description)
} catch {
print("🚫 An error occurred while setting the configuration: \(error)")
}
Result
After scanning a document through the Verifai flow,
the SDK will return a VerifaiCoreResult
object.
The object does not contain all of the information on a document.
It's meant to be used as a bridge to allow use of the Verifai API with other modules.
Or to return references provided when the scan was started.
The items in the results that might be of relevance for reference purposes are:
frontImage
: Picture of the front (UIImage)mrzData
: The MRZ data if any read from the document
The rest of the values get used to help other Verifai modules to perform Verifai compliant scans.
Errors
What follows is an overview of the errors Verifai can return with a description of what causes them.
Error | Type | Description | Possible solutions |
---|---|---|---|
flowCancelled | VerifaiFlowCancelError | The user cancelled out of the flow | Show an error condition or ask the user to retry |
neuralNetworkLoadingFailed | VerifaiFlowCancelError | Something went wrong loading the neural network | Make sure an internet connection is active and retry |
invalidConfiguration(_ description: String) | VerifaiConfigurationError | The configuration provided in Verifai.configure(with: is invalid. | Check the description in the error, fix your configuration and retry. |
permissionDenied | VerifaiCameraError | The user denied the camera permission request | Request your user to go to your app's setting and enable the camera permission |
slowNetwork(_ timeout: TimeInterval) | VerifaiNetworkError | A timeout on the network has been detected | Check your internet connection and retry |
invalidRequest(_ underlyingError: Error?) | VerifaiNetworkError | And invalid request was triggered by the OS | Check the underlying iOS error for more info |
downloadFailed(_ underlyingError: Error?) | VerifaiNetworkError | A download operation failed | Check the underlying iOS error for more info |