Get Started With Scandit ID Capture#

Quick overview#

ID Capture provides the capability to scan personal identification documents, such as identity cards, passports or visas. In this guide you will learn step by step how to add ID Capture to your application. Roughly, the steps are:

Note

Using ID Capture with other modes (e.g. Barcode Capture or Text Capture) is not supported.

Prerequisites#

Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you added the necessary dependencies. If you have not done that yet, check out this guide.

Note

You can retrieve your Scandit Data Capture SDK license key, by signing in to your account at ssl.scandit.com.

Please note that your license may support only a subset of ID Capture features. If you would like to use additional features please contact us at support@scandit.com.

Create the Data Capture Context#

The first step to add barcode capture capabilities to your application is to create a new data capture context. The context expects a valid Scandit Data Capture SDK license key during construction.

self.context = DataCaptureContext(licenseKey: "-- ENTER YOUR SCANDIT LICENSE KEY HERE --")

Adding the Camera#

You need to also create SDCCamera:

camera = Camera.default
context.setFrameSource(camera, completionHandler: nil)

let recommenededCameraSettings = IdCapture.recommendedCameraSettings
camera?.apply(recommenededCameraSettings)

Adding the Data Capture View#

Next, in order to actually see the camera feed on the screen, create an instance of SDCDataCaptureView and add it to your view hierarchy. For example:

captureView = DataCaptureView(context: context, frame: view.bounds)
captureView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(captureView)

Create ID Capture Settings#

Use SDCIdCaptureSettings to configure the types of documents that you’d like to scan. Check SDCIdDocumentType for all the available options.

idCaptureSettings.supportedDocuments = [.idCardViz, .aamvaBarcode, .dlViz]

Implementing the Listener#

To receive scan results, implement SDCIdCaptureListener. A result is delivered as SDCCapturedId. This class contains data common for all kinds of personal identification documents. For more specific information use its non-nil result properties (for example SDCCapturedId.aamvaBarcodeResult).

extension IdCaptureViewController: IdCaptureListener {
  func idCapture(_ idCapture: IdCapture, didCaptureIn session: IdCaptureSession, frameData: FrameData) {
    let capturedId = session.newlyCapturedId

    // The recognized fields of the captured Id can vary based on the type.
    if capturedId.mrzResult != nil {
        // Handle the information extracted.
    } else if capturedId.vizResult != nil {
        // Handle the information extracted.
    } else if capturedId.aamvaBarcodeResult != nil {
        // Handle the information extracted.
    } else if capturedId.usUniformedServicesBarcodeResult != nil {
        // Handle the information extracted.
    }
  }

  func idCapture(_ idCapture: IdCapture,
                didFailWithError error: Error,
                session: IdCaptureSession,
                frameData: FrameData) {
    // Handle the error.
  }
}

Create a new ID Capture mode with the chosen settings. Then register the listener:

idCapture = IdCapture(context: context, settings: idCaptureSettings)
idCapture.addListener(self)

The last thing that needs to be done is enabling the mode and turning on the camera:

camera?.switch(toDesiredState: .on)

And this is it. You can now scan documents.

Supported documents#

You can find the list of supported documents here.

What’s next?

To dive further into the Scandit Data Capture SDK we recommend the following articles: