DOT iOS Document 5.0.0

This guide describes how to migrate DOT iOS Document version 3.x to version 5.0. Only the most important changes are highlighted in this guide. For more details, see the iOS Samples.

Migration Steps

New SDK versioning

  • Replace individual versions of all libraries (DOT Document, DOT Face, DOT Face Lite and DOT NFC) with a single version name. Libraries with the same version name work correctly at build time and at run time.

Before

# Podfile

target 'TARGET' do
  use_frameworks!

  pod 'dot-face-detection-fast', '4.11.1'
  pod 'dot-document', '3.7.1'
  pod 'dot-nfc', '2.3.3'
  
end

After

# Podfile

target 'TARGET' do
  use_frameworks!

  pod 'dot-face-detection-fast', '5.0.0'
  pod 'dot-document', '5.0.0'
  pod 'dot-nfc', '5.0.0'
  
end

DocumentAutoCaptureViewController component

  • Added DocumentAutoCaptureConfiguration.QualityAttributeThresholds.
  • Removed deprecated DocumentAutoCaptureConfiguration.init()
  • Removed deprecated DocumentAutoCaptureConfiguration.cameraPreset. CameraPreset is no longer configurable from version 5.0.0.

Before

let minConfidence = 0.2
let minSize = 0.2
let minSharpness = 0.9
let minBrightness = 0.2
let maxBrightness = 0.8
let maxHotspotsScore = 0.008

let validationMode = ValidationMode.standard
let isMrzReadingEnabled = false
let isDetectionLayerVisible = false
let cameraFacing = DotDocument.CameraFacing.back
let cameraPreviewScaleType = DotDocument.CameraPreviewScaleType.fit
let cameraPreset = CameraPreset.fullHD

let configuration = try! DocumentAutoCaptureConfiguration(
    confidenceLowThreshold: minConfidence,
    sizeSmallThreshold: minSize,
    sharpnessLowThreshold: minSharpness,
    brightnessLowThreshold: minBrightness,
    brightnessHighThreshold: maxBrightness,
    hotspotsScoreHighThreshold: maxHotspotsScore,
    validationMode: validationMode,
    isMrzReadingEnabled: isMrzReadingEnabled,
    isDetectionLayerVisible: isDetectionLayerVisible,
    cameraFacing: cameraFacing,
    cameraPreviewScaleType: cameraPreviewScaleType,
    cameraPreset: cameraPreset
)

After

let minConfidence = 0.2
let minSize = 0.2
let minSharpness = 0.9
let minBrightness = 0.2
let maxBrightness = 0.8
let maxHotspotsScore = 0.008

let validationMode = ValidationMode.standard
let isMrzReadingEnabled = false
let isDetectionLayerVisible = false
let cameraFacing = DotDocument.CameraFacing.back
let cameraPreviewScaleType = DotDocument.CameraPreviewScaleType.fit

let qualityAttributeThresholds = try! DocumentAutoCaptureConfiguration.QualityAttributeThresholds(
    minConfidence: minConfidence,
    minSize: minSize,
    minSharpness: minSharpness,
    brightnessInterval: try! .init(min: minBrightness, max: maxBrightness),
    maxHotspotsScore: maxHotspotsScore
)
let configuratiom = DocumentAutoCaptureConfiguration(
    qualityAttributeThresholds: qualityAttributeThresholds,
    validationMode: validationMode,
    isMrzReadingEnabled: isMrzReadingEnabled,
    isDetectionLayerVisible: isDetectionLayerVisible,
    cameraFacing: cameraFacing,
    cameraPreviewScaleType: cameraPreviewScaleType
)

DocumentAutoCaptureController component

  • Removed DocumentAutoCaptureController.requestCapture(). Current DocumentAutoCaptureDetection can be used instead of a result from .requestCapture().
  • Removed delegate pattern, component now returns results synchronously.

Before

class DocumentAutoCaptureControllerHandler {

    var controller: DocumentAutoCaptureController?

    func createDocumentAutoCaptureController() {
        let configuration = try! DocumentAutoCaptureControllerConfiguration(
            validators: [
                DocumentNotDetectedValidator(),
                SizeSmallValidator(),
                SharpnessLowValidator()
            ]
        )
        let controller = DocumentAutoCaptureController(configuration: configuration)
        controller.delegate = self
        self.controller = controller
    }

    func process(bgraRawImage: BgraRawImage) {
        controller?.process(bgraRawImage: bgraRawImage)
    }
}

extension DocumentAutoCaptureControllerHandler: DocumentAutoCaptureControllerDelegate {

    func documentAutoCaptureController(_ controller: DotDocument.DocumentAutoCaptureController, detected detection: DotDocument.DocumentAutoCaptureDetection) {
        print("Detected: ", detection)
    }

    func documentAutoCaptureControllerCandidateSelectionStarted(_ controller: DotDocument.DocumentAutoCaptureController) {
        print("Candidate selection started")
    }

    func documentAutoCaptureController(_ controller: DotDocument.DocumentAutoCaptureController, captured result: DotDocument.DocumentAutoCaptureResult) {
        print("Captured: ", result)
    }
}

After

class DocumentAutoCaptureControllerHandler {

    var controller: DocumentAutoCaptureController?

    func createDocumentAutoCaptureController() {
        let configuration = try! DocumentAutoCaptureControllerConfiguration(
            validators: [
                DocumentNotDetectedValidator(),
                SizeTooSmallValidator(),
                SharpnessTooLowValidator()
            ]
        )
        self.controller = DocumentAutoCaptureController(configuration: configuration)
    }

    func process(bgraRawImage: BgraRawImage, timestampMillis: Int) throws {
        let processed = try controller!.process(bgraRawImage: bgraRawImage, timestampMillis: timestampMillis)
        print("Detected: ", processed.detection)
        print("Use detection to replace requestCapture(): ", processed.detection)
        if let result = processed.result {
            print("Captured: ", result)
        } else if processed.events.map({ $0.event }).contains(.candidateSelectionStarted) {
            print("Candidate selection started")
        }
    }
}