Document.RG_FRONT, // front of the ID, where the picture isDocument.RG_BACK, // back of the ID, where the data isDocument.RG_FULL, // open ID, showing both the front and the backDocument.CNH_FRONT, // the front of the CNH, where the picture isDocument.CNH_BACK, // the back of the CNH, where the signature isDocument.CNH_FULL, // open CNH, showing both the front and the backDocument.CRLV, // CRLVDocument.RNE_FRONT, // the front of the RNE and RNM, the part with the dataDocument.RNE_BACK, // back of the RNE and RNM, the part with the pictureDocument.PASSPORT, // PassportDocument.CTPS_FRONT, // front of the CTPSDocument.CTPS_BACK, // Back of the CTPSDocument.OTHERS, // other identification documents in general, such as RNE, Military ID, OAB, and CRLVDocument.ANY; // allows sending any capture
Required permissions
In the info.plist file, add the permissions below:
NSPhotoLibraryUsageDescription
Utilization
First, instantiate an object of type DocumentDetectorSdk:
let documentDetector = DocumentDetectorSdk.Builder(mobileToken:"mobileToken")// see table bellow .build()
DocumentDetectorSdk.Builder
DocumentDetectorStep
To create a capture flow, you will need to create an array of DocumentDetectorStep, where each element will be a capture step. To construct each DocumentDetectorStep object, you can enter the following elements:
MessageSettings
UploadSettings
To activate the document upload functionality it is necessary to instantiate an object of type UploadSettings() and set its parameters:
To get the result, you must implement the DocumentDetectorControllerDelegate delegate in your controller:
classYouController:UIViewController, DocumentDetectorControllerDelegate{// MARK: - Document Detection Delegates func documentDetectionController(_ scanner: DocumentDetectorController, didFinishWithResults results: DocumentDetectorResult) {
//Called when the process was successfully executed//The result variable contains the data obtained }funcdocumentDetectionControllerDidCancel(_scanner: DocumentDetectorController) {// Called when the user cancel } func documentDetectionController(_ scanner: DocumentDetectorController, didFailWithError error: DocumentDetectorFailure) {
//Called when the process terminate with an error//The error variable contains info about error }}
After creating the DocumentDetector object, start the DocumentDetectorController by passing this object as a parameter in the constructor:
let scannerVC =DocumentDetectorController(documentDetector: documentDetector)scannerVC.documentDetectorDelegate = selfpresent(scannerVC, animated:true, completion:nil)
DocumentDetectorResult
Capture
DocumentDetectorFailure
Superclass that leads to the SDK shutdown. To find out what the reason was, find out which object class has the **isKindOfClass() ** method, equivalent to instanceof in Java and is in Dart:
Examples
Customizing the Layout
You can customize the layout by creating an object of type DocumentDetectorLayout and passing it as a parameter in DocumentDetectorBuilder:
Identifier of the user for the purpose of identifying a fraudulent profile
No, only used for analytics
.setAnalyticsSettings(useAnalytics: Bool)
Enables/disables data collection for analytics
No, the default is true
.setPopupSettings(show: Bool)
Change the setting of the inflated popups before each document
No, the default is true
.setDetectionSettings(detectionThreshold : Float)
Changes the default document detection setting, the frame confidence threshold (from 0.0 to 1.0, where 1.0 indicates that the SDK will only accept the document with a perfect frame)
Changes the default setting for verifying the quality of the captures, indicating whether you want to perform this verification (takes about 2 seconds) and the quality threshold for these photos can be set (value from 1.0 to 5.0). In addition, the SDK will return the URL of the image in the variable DocumentDetectorResult.Capture.ImageUrl. Be careful, if you decide to check the quality in this parameter and there is a connection failure while sending the images, the SDK will terminate with an internet error.
No. The default is true and 1.8, respectively
.setLayout(layout: DocumentDetectorLayout)
Changes the document masks from success, failure, and normal.
It also allows you to change the sound and cancel buttons at the top of the screen. See the example.
No
.setColorTheme(color: UIColor)
Change the color of the sound and cancel buttons that are at the top of the screen. Also change the color of the popup buttons, inflated before each document.
No
.enableSound(enableSound: Bool)
Enables/disables sounds and the sound icon in the SDK
No, the default is true
.showStepLabel(show: Bool)
Show/hide the lower middle label (which contains the document name)
No, the default is true
.showStatusLabel(show: Bool)
Show/hide the central label (which contains the status)
Defines threshold between correct/incorrect device orientation. Higher the value more flexible it will be. The threshold of this sensor is the acceleration of the device
Changes the default settings of the stability sensor. The threshold of this sensor is in the range of the last two accelerations collected from the device.
Enables/disables the capture preview. If show has true, after each capture, the SDK provides a screen for the user to approve or make the capture again. For the remaining parameters, enter nil to use the default value or a String for a custom text.
Allows customizing messages displayed in the "status" balloon during the capture and analysis process. example
No.
.setCompressSettings(compressionQuality: CGFloat)
Allows you to set the quality in the compression process. By default, all captures are compressed. The method expects values between 0 and 1.0 as parameters, 1.0 being the best quality compression (recommended).
Delay the activity after the completion of each step. This method can be used to display a success message on the screen itself after the capture, for example.
No. The default is false
.setUploadSettings(UploadSettings uploadSettings)
Sets the settings for uploading documents. By enabling this option, the SDK flow will prompt the user to upload the document files instead of capturing them with the device's camera. This option also includes document quality checks. example of implementation.
No. By default this option is disabled.
.setResolutionSettings(resolution: Resolution)
Allows you to set the capture resolution. The method takes a parameter a Resolution, which has the following options:
low Specifies appropriate capture settings for output video and audio bit rates suitable for 3G sharing
medium Specifies the appropriate capture settings for the output video and audio bitrates suitable for sharing over WiFi
high Specifies appropriate capture settings for high-quality video and audio output
photo Specifies appropriate capture settings for high-resolution photo quality output
inputPriority Specifies appropriate capture settings for high-resolution photo quality output
hd1280x720 Specifies the appropriate capture settings for video output at 720p quality (1280 x 720 pixels)
hd1920x1080 Capture settings suitable for 1080p (1920 x 1080 pixels) quality video output
hd4K3840x2160 Capture settings suitable for 2160p (3840 x 2160 pixels) quality video output
No. Passports issued by any country are accepted by default.
Parameter
Required?
document: Document
Identifies which document you want to capture in the respective step
Yes
stepLabel: String?
Text to be displayed at the bottom of the layout
No. There is a pattern per Document Type
illustration: UIImage?
Illustration to be shown in the popup before the capture
No. There is a pattern per Document Type
audio: URL?
Audio to be played at the beginning of the step. Example.
No. There is a pattern per Document Type
Attribute
Default Value
waitMessage: String
Message displayed when SDK is in the process of opening.
"Please Wait…"
fitTheDocumentMessage: String
Message advising to fit the document to the mask.
"Fit the document on the markup"
verifyingQualityMessage: String
Message displayed when the SDK makes a request to the backend, verifying quality.
"Checking Quality…"
lowQualityDocumentMessage: String
Message displayed when the quality of the capture fails.
"Ops, could not read the information. Please try again"
uploadingImageMessage: String
Message displayed when there is no quality check and the capture is being saved on the servers.
"Sending Image…"
popupDocumentSubtitleMessage: String
Text displayed in the step initialization popup.
"Dispose the document in a desk, centralize it on the markup and hold the automatic capture."
unsupportedDocumentMessage: String
Message displayed when a unexpected type of document is displayed for capture.
"Ops, it seems that this document is not supported. Contact us!"
wrongDocumentMessage_RG_FRONT: String
Message displayed when the front of the RG(Brazilian ID card) is displayed in a different flow than expected.
"Ops, this is the RG's Front"
wrongDocumentMessage_RG_BACK: String
Message displayed when the RG(Brazilian ID card) version is displayed in a different flow than expected.
"Ops, this is the RG's Back"
wrongDocumentMessage_RG_FULL: String
Message displayed when the open RG(Brazilian ID card) is displayed in a different stream than expected.
"Ops, this is the RG Opened"
wrongDocumentMessage_CNH_FRONT: String
Message displayed when the front of the CNH(Brazilian driver's license) is displayed in a different stream than expected.
"Ops, this is the CNH's Front"
wrongDocumentMessage_CNH_BACK: String
Message displayed when the version of the CNH(Brazilian driver's license) is displayed in a different stream than expected.
"Ops, this is the CNH's Back"
wrongDocumentMessage_CNH_FULL: String
Message displayed when the open CNH(Brazilian driver's license) is displayed in a different stream than expected.
"Ops, this is the CNH Opened"
wrongDocumentMessage_CRLV: String
Message displayed when the CRLV(Brazilian Vehicle Registration and Licensing Certificate) is displayed in a different stream than expected.
"Ops, this is the CRLV"
wrongDocumentMessage_RNE_FRONT: String
Message displayed when the front of the RNE(National Registry of Foreigners) is displayed in a different stream than expected.
"Ops, this is the RNE's Front"
wrongDocumentMessage_RNE_BACK: String
Message displayed when the back of the RNE(National Registry of Foreigners) is displayed in a different stream than expected.
"Ops, this is the RNE's Back"
sensorLuminosityMessage: String
Message displayed when the brightness threshold is lower than expected.
"Area near you is too dark"
sensorOrientationMessage: String
Message displayed when the orientation threshold is lower than expected.
"The device is not on the horizontal"
sensorStabilityMessage: String
Message displayed when the orientation threshold is lower than expected.
"Keep the device still"
Parameter
Required?
enable
Enables/disables this feature.
No. The default is true
compress
Enables/disables file compression before uploading.
No. The default is true
fileFormats
Defines the file format(s) that will be accepted for upload.
No. By default .PDF , .JPEG and .PNG are accepted
maximumFileSize
Sets the maximum KB limit of the file to upload.
No. The default limit is 10000 KB (10MB).
Parameter
Can it be null?
captures:[Capture]
The array with the respective captures of the parameterized documents
Yes, in case of error
type: String
The class of the read document stream. This parameter is useful in an integration with our OCR route. The existing types are: ["blank", "cnh", "cnh_new", "generic", "rg", "rg_new", "rne", "rnm", "ctps", "passport, crlv, crlv_new"]
Yes, in case of error
trackingId: String?
Identifier of this run on our servers. If possible, save this field and send it along to our API. This way we will have more data about how the user behaved during the execution
Yes, if the user sets useAnalytics = false or the analytics calls do not work
Parameter
Can it be null?
image: UIImage
Document image
No
imageUrl :String
URL of the document on CAF's server. If you want this URL, keep enabled the parameter that checks the image quality
Yes, if you choose not to check the image quality
scannedLabel :String
Label of the respective document within the following possibilities: ["blank", "cnh_back", "cnh_front", "cnh_full", "new_cnh_back", "new_cnh_front", "new_cnh_full", "crlv", "crlv_new", "generic", "rg_back", "rg_front", "rg_full", "rg_new_back", "rg_new_front", "rg_new_full", "rne_back", "rne_front", "rnm_back", "rnm_front", "ctps_back", "ctps_front", "passport"]
No
quality :Double
Quality inferred by the document quality algorithm, when enabled. Varies between 1.0 and 5.0
May be 0, if the SDK does not check for quality
lensFacing: Int
Defines the face of the camera that was used. Use DocumentDetectorResult.LENS_FACING_FRONT or DocumentDetectorResult.LENS_FACING_FRONT to validate.
No
isKindOfClass()
Description
Exemple
InvalidTokenReason
The token entered is not valid for the corresponding product
Parameterize "test123" as token in the SDK builder
PermissionReason
You are missing some mandatory permission to run the SDK
Start DocumentDetector without camera permission granted
NetworkReason
Internet connection failure
User was without internet during facematch in FaceAuthenticator
ServerReason
When an SDK request receives a status code of failure
In theory, it shouldn't happen. If it does, let us know!
StorageReason
There is no space on the user device's internal storage
When there is no space on the internal storage while capturing the document photo