Initial Integration

Note

The SDK must be initialized before starting any capture sessions. To get started, see Installation.

Scanning Documents

Document capture sessions are managed by a DSHandler. For every capture session, you must cover 3 steps:

  1. Configure and set the DSHandler.options

  2. Present the DSHandler.scanController

  3. Respond to DSHandlerDelegate invocations

import UIKit
import CFDocumentScanSDK

class ViewController: UIViewController, DSHandlerDelegate {

    private lazy var scanHandler = DSHandler(delegate: self)

    func startScan(options: DSOptions) {
        scanHandler.options = options
        present(scanHandler.scanController, animated: true)
        scanHandler.start()
    }

    // MARK: - DSHandlerDelegate

    func handleScan(result: DSResult) {
        print("Scan Result: \(result)")
    }

    func captureError(_ error: DSError) {
        print("Scan Error: \(error)")
    }

}

Document capture options are highly configurable, but every capture is broken down into one of two categories: ID1 and ID3.

Card Documents (ID1)

Card-shaped documents, such as drivers licenses and passport cards, are referred to as ID1 Documents. To start an ID1 capture session, you need to provide a DSID1Options to your DSHandler:

import UIKit
import CFDocumentScanSDK

class ViewController: UIViewController, DSHandlerDelegate {

    // ...

    func startID1Scan() {
        let options = DSID1Options()
        // Configure capture options, thresholds, prompts, etc.
        options.side = .Front

        startScan(options: options)
    }

}

Passport Documents (ID3)

Passport-shaped documents are referred to as ID3 Documents. To start an ID3 capture session, you need to provide a DSPassportOptions to your DSHandler:

import UIKit
import CFDocumentScanSDK

class ViewController: UIViewController, DSHandlerDelegate {

    // ...

    func startID1Scan() {
        let options = DSPassportOptions()
        // Configure capture options, thresholds, prompts, etc.

        startScan(options: options)
    }

}

Auto Capture Setup

By default the SDK capture mode is set to .Manual. For auto capture, you must change the default setting in code. In auto capture mode, the SDK will revert to manual capture after a set amount of time (in seconds). This time is controlled by the autoCaptureTimeoutDuration parameter, which defaults to 30s. Example setup is shown below:

let options = DSID1Options() // or DSPassportOptions()
options.captureMode = .Auto
options.autoCaptureTimeoutDuration = 30 // Default
// continue options setup ...

We recommend including an option to switch back to manual mode, for the case where the user is having difficulty using auto capture.

For more details, see Capture Modes.

Important

To achieve best capture results, please capture in a well lit environment, with contrasting background, and have the capture device be parallel with the document.