DocumentDetector v9.x or above

Current Version

Requirements

Required permissions

In the info.plist file, add the permissions below:

SDK size

The SDK will add approximately 8 MB to your final app.

Installation

CocoaPods

In your Podfile, specify the reference to our framework. Replacing <version> with the current version:

target 'your-project' do
  use_frameworks!

  pod 'DocumentDetector', '<version>'

SPM

  1. Open your Xcode project.

  2. Navigate to File > Add Packages.

  3. In the search bar, paste the URL of this repository:

https://github.com/combateafraude/DocumentDetector.git

Supported documents

Currently supported documents are:

Document.RG_FRONT, // front of RG (where the photo is located)
Document.RG_BACK, // back of RG
Document.RG_FULL, // RG opened (showing front and back together)
Document.CNH_FRONT, // front of CNH (where the photo is located)
Document.CNH_BACK, // back of CNH
Document.CNH_FULL, // CNH opened (showing front and back together)
Document.CRLV, // CRLV
Document.RNE_FRONT, // front of RNE or RNM
Document.RNE_BACK, // back of RNE or RNM
Document.PASSPORT, // passport (showing the photo and data)
Document.CTPS_FRONT, // front of CTPS (where the photo is located)
Document.CTPS_BACK, // back of CTPS
Document.ANY; // allows you to send any type of document, all those mentioned above, including any other document, as there are no typifications

Instantiating the SDK

First, instantiate an object of type DocumentDetectorSdk:

let documentDetector = DocumentDetectorSdk.CafBuilder(mobileToken: "mobileToken")
    // see table bellow
    .build()

We recommend paying special attention to the SDK implementation for low-end devices. For better performance and user experience, consider using the document upload flow instead of the capture mode.

Another point of attention: please note that the automatic document capture option is only available for devices with iOS 13+. Below this version, the SDK will only enable the manual document capture option.

DocumentDetector Options

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:

Customizing layout

You can customize the layout by creating an object of type DocumentDetectorLayout and passing it as a parameter in setLayout(). The DocumentDetectorLayout elements are:

Example

let layout = DocumentDetectorLayout()
                        
layout.closeButtonImage = UIImage(named: "my_close_image")
layout.closeButtonColor = .green
layout.closeButtonSize = CGFloat(50)
layout.closeButtonContentMode = .scaleAspectFill

layout.font = "my_font"

layout.primaryColor = .blue
layout.feedbackColors = DocumentFeedbackColors(defaultColor: .black, errorColor: .red, successColor: .green)

let documentDetector = DocumentDetectorSdk.CafBuilder(mobileToken: "mobileToken")
    .setDocumentCaptureFlow(flow: [DocumentDetectorStep(document: Document.CNH_FRONT), DocumentDetectorStep(document: Document.CNH_BACK)])
    .setLayout(layout: layout)
    .build()

MessageSettings

.setMessageSettings(
    waitMessage: String?, 
    fitTheDocumentMessage: String?, 
    verifyingQualityMessage: String?, 
    lowQualityDocumentMessage: String?, 
    uploadingImageMessage: String?, 
    popupDocumentSubtitleMessage: String?, 
    unsupportedDocumentMessage: String?, 
    wrongDocumentMessage: String?, 
    sensorLuminosityMessage: String?, 
    sensorOrientationMessage: String?, 
    sensorStabilityMessage: String?, 
    predictorScanDocumentMessage: String?, 
    predictorGetCloserMessage: String?, 
    predictorCentralizeMessage: String?,
    predictorMoveAwayMessage: String?, 
    predictorAlignDocumentMessage: String?, 
    predictorTurnDocumentMessage: String?, 
    predictorCapturedMessage: String?
)

CafUploadSettings

To activate the document upload functionality it is necessary to instantiate an object of type CafUploadSettings() 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

CafCapture

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:

Last updated

Logo

2023 © Caf. - All rights reserved