DocumentDetector v8.x or below

Supported documents

Currently, the documents supported on iOS are:

Document.RG_FRONT, // front of the ID, where the picture is
Document.RG_BACK, // back of the ID, where the data is
Document.RG_FULL, // open ID, showing both the front and the back
Document.CNH_FRONT, // the front of the CNH, where the picture is
Document.CNH_BACK, // the back of the CNH, where the signature is
Document.CNH_FULL, // open CNH, showing both the front and the back
Document.CRLV, // CRLV
Document.RNE_FRONT, // the front of the RNE and RNM, the part with the data
Document.RNE_BACK, // back of the RNE and RNM, the part with the picture
Document.PASSPORT, // Passport
Document.CTPS_FRONT, // front of the CTPS
Document.CTPS_BACK, // Back of the CTPS
Document.OTHERS, // other identification documents in general, such as RNE, Military ID, OAB, and CRLV
Document.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:

Currently, the supported file formats are:

public enum FileFormat: String {
    case png
    case jpeg
    case pdf
}

Getting the result

To get the result, you must implement the DocumentDetectorControllerDelegate delegate in your controller:

class YouController: 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
    }
    
    func documentDetectionControllerDidCancel(_ 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 = self
present(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:

let layout = DocumentDetectorLayout()

layout.changeMaskImages(
    greenMask: UIImage(named: "my_green_mask"),
    whiteMask: UIImage(named: "my_white_mask"),
    redMask: UIImage(named: "my_red_mask"))

layout.changeSoundImages(soundOn: UIImage(named: "my_sound_on_image"),
                        soundOff: UIImage(named: "my_sound_off_image"))
                        
layout.closeImage = UIImage(named: "my_close_image")
layout.buttonSize = CGFloat(50)
layout.buttonContentMode = .scaleAspectFill

layout.setFont = UIImage(named: "my_font")

let documentDetectorConfiguration = DocumentDetectorBuilder(apiToken: "API_TOKEN")
    .setDocumentDetectorFlow(flow: DocumentDetectorBuilder.RG_FLOW)
    .setLayout(layout: layout)
    .build()

How to get the URL of an audio

let bundle = Bundle.init(for: type(of: self))
let audioURL = URL(fileURLWithPath: bundle.path(forResource: "my_audio_file", ofType: "mp3")!)

Last updated

Logo

2023 © Caf. - All rights reserved