BlinkID iOS SDK Documentation

repository·master·Indexed 19 days ago

https://github.com/microblink/blinkid-ios

An iOS SDK for high-performance document scanning and data extraction, including MRZ, barcodes, and visual field inspection. The SDK consists of the core BlinkID framework for scanning and analysis, and an optional BlinkIDUX package providing a ready-to-use SwiftUI user interface. It supports modern iOS development using Swift 6 and concurrency features, requiring iOS 15.0+ for the core SDK and iOS 16.0+ for the UX package.

Tokens
33.2K
Snippets
74
Records
179
Agent score
64%

What's inside BlinkID iOS SDK

  1. Overview of BlinkID SDK

    master

    The BlinkID SDK is a solution for secure document scanning on iOS, capable of capturing and analyzing various identification documents. It consists of two main parts:

    • BlinkID: The core framework providing scanning and analysis capabilities.
    • BlinkIDUX: An optional package providing a ready-to-use user interface (UX) for the scanning process.

    Supported documents and result fields are documented in the Microblink documentation.

  2. BlinkID SDK size and footprint

    master

    The BlinkID SDK is lightweight with a compressed download size of approximately 2.4 MB. When installed on a device, the uncompressed size is approximately 5.5 MB.

    Size measurements are based on Xcode App Size Reports. You can view the detailed size reports in the repository's size-report directory.

  3. Handle nullability in ID result classes

    master

    Starting from version 2.5.1, the SDK uses strict nullability annotations for all result class getters.

    • If a getter returns nil, it means no data exists for that specific field on the scanned document.
    • If a getter returns an empty string (@""), it means the field exists on the document but is empty.
  4. Implement Redaction to Anonymize Scanned Data

    master

    Redaction allows you to anonymize sensitive data before the scanning result is finalized. You can apply redaction globally via RedactionSettings or dynamically per document using a RedactionSettingsResolver.

    // Example of static RedactionSettings
    let redaction = RedactionSettings(
        mode: .fullResult,
        fields: [.additionalAddressInformation, .additionalPersonalIdNumber],
        documentNumberRedactionSettings: DocumentNumberRedactionSettings(
            prefixDigitsVisible: 0,
            suffixDigitsVisible: 4
        ),
        redactMrz: true,
        redactBarcode: false
    )
  5. Understand ProcessResult and Scanning Status

    master

    The ProcessResult structure encapsulates the complete results of a scanning process, including frame analysis and completeness information.

    Key Components

    InputImageAnalysisResult

    Provides detailed analysis of a single frame:

    • processingStatus: Overall status for the frame.
    • documentDetectionStatus: Status of document detection (e.g., .success, .cameraTooFar, .documentPartiallyVisible).
    • documentLocation: A Quadrilateral representing the document's position in the image.
    • documentClassInfo: Details about the detected document (country, region, type).

    ScanningStatus

    Retrieved via session.getScanningStatus(), this tracks the lifecycle of the scanning operation:

    • .scanningSideInProgress: A document side is being scanned.
    • .scanningBarcodeInProgress: The barcode is being scanned.
    • .sideScanned: A side has been completed.
    • .documentScanned: The entire document is complete.
    • .cancelled: The process was cancelled.

    ResultCompleteness

    Tracks which components have been successfully extracted:

    • viz: Completeness of VIZ extraction.
    • mrz: Completeness of MRZ extraction.
    • barcode: Completeness of barcode extraction.
    • faceImage, signatureImage, barcodeImage, documentImages: Completeness of various image extractions.
  6. Identify scanning failure reasons via AdditionalProcessingInfo

    master
    In version 6.10.0, the AdditionalProcessingInfo field was updated to provide specific details about why a scan failed in cases where the result is empty. This can be used to debug or provide user feedback when document recognition does not succeed.
  7. Use GlareDetector to prevent OCR errors

    master

    The GlareDetector is available in version 2.12.0 and is used by default in all recognizers whose settings implement GlareDetectorOptions. When glare is detected, the SDK will not perform OCR on the affected document position to prevent data errors.

    • To disable the glare detector, set the detectGlare property to false on the recognizer settings.
    • If enabled, glare metadata can be obtained if configured in MetadataSettings.
  8. Access structured OCR and Barcode results

    master

    In version 5.6.0, the result structure for MBBlinkIdRecognizer and MBBlinkIdCombinedRecognizer was reorganized for better data access:

    • MBBarcodeResult: Barcode data is now encapsulated in its own structure.
    • MBVizResult: Data from all OCR-ed fields (excluding MRZ) is encapsulated in a 'Visual Inspection Zone' structure.
    • Side-specific data: In MBBlinkIdCombinedRecognizer, you can access front-side data via frontVizResult and back-side data via backVizResult separately.

    Data Priority Logic: The main result object is populated using the following hierarchy:

    1. Document number (from MRZ, if present).
    2. Barcode data.
    3. Back side visual inspection zone (OCR outside MRZ).
    4. Front side visual inspection zone.
    5. Remaining MRZ data.
  9. Manage document scanning with BlinkIDSession

    master

    A BlinkIDSession manages the lifecycle of a document scanning workflow, including image processing, analysis, and result generation.

    Important Integration Notes:

    • Actor Isolation: Most methods (like process and getResult) must be called within the @ProcessingActor context to ensure thread safety.
    • Thread Safety: The class implements Sendable and uses actor isolation for concurrent environments.
    • Cancellation: You can call cancelActiveProcessing() at any time to terminate ongoing operations.
    /// Processes a camera frame for document analysis.
    /// - Parameter image: The camera frame to analyze
    public func analyze(image: CameraFrame) async {
        guard !paused else {
            return 
        }
        let inputImage = InputImage(cameraFrame: image)
    
        let result = await BlinkIDSession.process(inputImage: inputImage)
    
        if result.processResult?.inputImageAnalysisResult.processingStatus == .success {
            Task { @ProcessingActor in
                let sessionResult = session.getResult()
                // Finish scanning
            }
        }
    }
  10. Compare resource deletion methods

    master

    Choose the appropriate method for clearing caches based on the current state of the SDK:

    FeaturedeleteCachedResources(...)
    Terminates the SDKNo (deletes files only)
    Requires active instanceNo (static utility)
    Folder locationFrom parameters (must match config)
    Actor requirementNone
    Risk of wrong folderPossible if names mismatch
    FeatureterminateBlinkIDSdkAndDeleteCachedResources()
    Terminates the SDKYes
    Requires active instanceYes (no-op if no instance exists)
    Folder locationFrom the live instance's actual paths
    Actor requirementMust be in ProcessingActor
    Risk of wrong folderNone

    Summary Recommendation:

    • SDK is running and you want to shut down + wipe: Use terminateBlinkIDSdkAndDeleteCachedResources().
    • SDK is not running and you just want to clear files: Use deleteCachedResources(...) with your configured folder names.