Skip to content

Using EUDL recognizer in Swift

dino.gustin edited this page Jun 14, 2016 · 1 revision

EUDL recognizer is responsible for scanning, decoding and parsing front side of EU Driving licenses - EUDLs

If you completed Obtaining scanning results guide, you learned that in order to use a specific recognizer, you need to specify Recognizer Settings object in the initialization stage, and collect Recognizer Result object in the success callback.

Here we explain how to use EUDL recognizer, it's settings class PPEudlRecognizerSettings, and result class PPEudlRecognizerResult to obtain Driver's license information from the scanning results.

Back to "Getting started" guide.

Initializing the scanning of UK driver's licenses

Below is the sample source code which initializes the scanning for EU driver's licenses.

// 3. ************* Setup Scan Settings **************/

// To specify we want to perform EUDL (EU Driving license) recognition, initialize the EUDL recognizer settings
// Initializing with PPEudlCountryAny performs the scanning for all supported EU driver's licenses, while initializing with a specific EUDL country (i.e. PPEudlCountryGermany) performs the scanning only for UK dirver's licenses
let eudlRecognizerSettings = PPEudlRecognizerSettings(eudlCountry: PPEudlCountry.UnitedKingdom)

// Add EUDL Recognizer setting to a list of used recognizer settings
settings.scanSettings.addRecognizerSettings(eudlRecognizerSettings)

Retrieving results

By default, scanningViewController:didOutputResults: callback returns results as a PPRecognizerResults object. When the instance of this result is of type PPEudlRecognizerResult, this means we got the result of EUDL scanning and parsing.

Below is the sample source code which demonstrates how to collect results of EUDL scanning.

func scanningViewController(scanningViewController: UIViewController?, didOutputResults results: [PPRecognizerResult]) {

    let scanController : PPScanningViewController = scanningViewController as! PPScanningViewController

    // Here you process scanning results. Scanning results are given in the array of PPRecognizerResult objects.

    // first, pause scanning until we process all the results
    scanController.pauseScanning()


    // Collect data from the result
    for result in results {
        if(result.isKindOfClass(PPEudlRecognizerResult)) {

            // Cast result to PPEudlRecognizerResult
            let eudlResult : PPEudlRecognizerResult = result as! PPEudlRecognizerResult

            // Fields of the driver's license can be obtained by using methods defined in PPUkdlRecognizerResult.h header file

            // for First name, use ownerFirstName method
            print("First name: %@\n",eudlResult.ownerFirstName())

            // for Last name, use ownerLastName method
            print("Last names: %@\n",eudlResult.ownerLastName())

            // for Address, use ownerAdress method
            print("Address: %@\n",eudlResult.ownerAdress())

            // for Birth data, use ownerBirthData method
            print("Birth data: %@\n",eudlResult.ownerBirthData())

            // for Document issue date, use documentIssueDate method
            print("Document issue date: %@\n",eudlResult.documentIssueDate())

            // for Document exipiry date, use documentExpiryDate method
            print("Document expiry date: %@\n",eudlResult.documentExpiryDate())

            // for Driver number, use driverNumber method
            print("Driver number: %@\n",eudlResult.driverNumber())
      }
    }

    // either resume scanning, or dismiss Scanning View controller
    // scanningViewController.resumeScanningAndResetState(true)
    scanningViewController.dismissViewControllerAnimated(true, completion:nil)
}
Clone this wiki locally