Get Started With the ID Scanning#

This guide will briefly explain how to use the Scandit SDK for Id Scanning. Steps covered in this document are :

Supported documents#

Currently only AAMVA formats are supported for parsing data encoded in PDF417 barcodes. See more in: AAMVA Driver License/Identification. List of supported MRTD codes: ICAO Machine Readable Travel Document (parser/MRTD).

Add DLID scanner and parser#

First what you need to do is to set a barcode scanner for reading PDF417 barcodes and DLID parser:

let context = DataCaptureContext(licenseKey: licenseKey)
let camera = Camera.default

camera?.apply(BarcodeTracking.recommendedCameraSettings, completionHandler: nil)
context.setFrameSource(camera, completionHandler: nil)

let barcodeCaptureSettings = BarcodeCaptureSettings()
barcodeCaptureSettings.set(symbology: .pdf417, enabled: true)
barcodeCapture = BarcodeCapture(context: context, settings: barcodeCaptureSettings)

parser = try Parser(context: context, format: .dlid)

Then you need to conform to the SDCBarcodeCaptureListener protocol and add it to SDCBarcodeCapture:

func barcodeCapture(_ barcodeCapture: BarcodeCapture, didScanIn session: BarcodeCaptureSession, frameData: FrameData) {
    guard let barcode = session.newlyRecognizedBarcodes.first, let data = barcode.data else { return }

    parser = try! Parser(context: context, format: .dlid)
    let parsedData = parser.parseString(data)

    // Do something with parsedData.
}
barcodeCapture.addListener(self)

Add MRZ scanner and MRTD parser#

The MRTD parser needs regexes to be specified. You can find the list of regex patterns here.

let PASSPORT_REGEX = "INSERT_REGEX_HERE"
let TD1_REGEX = "INSERT_REGEX_HERE"
let REGEX = "(\(PASSPORT_REGEX)|\(TD1_REGEX)|\(other regexes...))"
let CHAR_WHITELIST = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<"
let SETTINGS_JSON = "{ \"regex\" : \"\(REGEX)\", \"characterWhitelist\" : \"\(CHAR_WHITELIST)\"}"

You need to set a text capture for reading MRZ and a MRTD parser:

let context = DataCaptureContext(licenseKey: licenseKey)
let camera = Camera.default

camera?.apply(TextCapture.recommendedCameraSettings, completionHandler: nil)
context.setFrameSource(camera, completionHandler: nil)

let textCaptureSettingsJson = SETTINGS_JSON

let textCaptureSettings = try! TextCaptureSettings(jsonString: textCaptureSettingsJson)

let textCapture = TextCapture(context: context, settings: textCaptureSettings)
parser = try Parser(context: context, format: .mrtd)

Then you need to conform to the SDCTextCaptureListener protocol and add it to SDCTextCapture:

 func textCapture(_ textCapture: TextCapture, didCaptureIn session: TextCaptureSession, frameData: FrameData) {
    //Pause the running TextCapture while processing the captured text.
    textCapture.isEnabled = false
    guard let text = session.newlyCapturedTexts.first?.value else {
      self.textCapture.isEnabled = true
      return
    }

    let message: String
    do {
      let parsedData = try parser.parseString(text)
      message = parsedData.fields.reduce("") { (result, field) -> String in
          guard let parsed = field.parsed else { return result }
          return "\(result) \n\(field.name): \(parsed)"
      }
    } catch {
      message = error.localizedDescription
    }

    // Show the parsed data.
    DispatchQueue.main.async {
      let alert = UIAlertController(title: "Parser result", message: message, preferredStyle: .alert)
      alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { _ in
        self.textCapture.isEnabled = true
      }))
      self.present(alert, animated: true, completion: nil)
    }
}
textCapture.addListener(self)