Integrate Document Scan SDK for iOS
Scan Documents
Document capture sessions are managed by a DSHandler. For every capture session, you must cover 3 steps:
-
Configure and set the DSHandler.options.
-
Present the DSHandler.scanController.
-
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:
-
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, provide a DSID1Options to your DSHandler:
Copyimport UIKit
import CFDocumentScanSDK
class ViewController: UIViewController, DSHandlerDelegate {
// ...
func startID1Scan() {
let options = DSID1Options()
// Conf igure capture options, th resholds, 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, provide a DSPassportOptions to your DSHandler:
Copyimport UIKit
import CFDocumentScanSDK
class ViewController: UIViewController, DSHandlerDelegate {
// ...
func startID1Scan() {
let options = DSPassportOptions()
// Conf igure capture options, th resholds, prompts, etc.
startScan(options: options)
}
}
Set Up Auto Capture
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 // Def ault
// 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.