Driving License


Examples Source Code

The source code of all example use cases of the ID Plugin can be found in the iOS SDK Bundle

Plugin Description

Simultaneous Barcode Scanning

Starting from SDK 3.8 Anyline supports simultaneous barcode scanning for any Plugin. Additional Information on how to implement this on iOS can be found at Simultaneous Barcode Scanning

The Anyline ID Plugin provides the functionality to scan passports and other IDs holding a Machine Readable Zone (MRZ) and Austrian Driving licenses.

For each scan result, the Plugin generates an Identification object, containing all relevant information as well as the image of the scanned document.

The description of all parameters can be found at Plugins > ID

How to implement the ID Plugins

This is a step by step guide on how to implement the ID Plugins in iOS.

Add the Anyline ID Plugins to your UIViewController

The first step is to add the three main components of every Anyline use case: the Scan Plugin (handling the scanning part), the Scan View Plugin (handling the UI) and the Scan View (handling camera, flash and overall communication between Anyline components).

Add the Anyline ID Plugins
// The Anyline module used to scan machine readable zones
@property (nonatomic, strong) ALIDScanViewPlugin *drivingLicenseScanViewPlugin;
@property (nonatomic, strong) ALIDScanPlugin *drivingLicenseScanPlugin;
@property (nullable, nonatomic, strong) ALScanView *scanView;

Anyline ScanPlugin

Initialise the Scan Plugin

You have to initialise the plugin with your Anyline License Key Generation, an ID (String) and the delegate inside viewDidLoad.

Initialise the Scan Plugin
    NSError *error = nil;
    self.drivingLicenseScanPlugin = [[ALIDScanPlugin alloc] initWithPluginID:@"ModuleID" licenseKey:kDrivingLicenseLicenseKey delegate:self idConfig:drivingLicenseConfig error:&error];
    NSAssert(self.drivingLicenseScanPlugin, @"Setup Error: %@", error.debugDescription);

Anyline ScanViewPlugin

Initialise the Scan View Plugin

After initialising the scanPlugin, the next step is to create the scanViewPlugin with the scanPlugin you just created. The ScanViewPlugin will handle and display the UI used for scanning.

Initialise the Scan View Plugin
    self.drivingLicenseScanViewPlugin = [[ALIDScanViewPlugin alloc] initWithScanPlugin:self.drivingLicenseScanPlugin];

Set the ScanViewPluginConfig

The View Configuration configurates the look and feel of the scanning process. You can set it the following way:

Set the ScanViewPluginConfig
NSString *confPath = [[NSBundle mainBundle] pathForResource:@"mrz_capture_config" ofType:@"json"];
ALScanViewPluginConfig *scanViewPluginConfig = [ALScanViewPluginConfig configurationFromJsonFilePath:confPath];

self.idScanViewPlugin = [[ALIDScanViewPlugin alloc] initWithScanPlugin:self.idScanPlugin
                                              scanViewPluginConfig:scanViewPluginConfig];

Limitations for the ID Plugin

The Ratio is fixed and optimised for the best results

Anyline ScanView

Initialise the Scan View

The last Anyline Object you have to create is the so called scanView, it will handle the camera, the flash and manage the previously created ScanViewPlugin and ScanPlugin. You need to instantiate the scanView with the previous created scanViewPlugin and the frame it should occupy. Usually, that’s the bounds of the screen.

Initialise the Scan View
    self.scanView = [[ALScanView alloc] initWithFrame:frame scanViewPlugin:self.drivingLicenseScanViewPlugin];

Adding the Scan View to the View Hierarchy and start the Camera Feed

To add the scanView to your view hierarchy add the following in viewDidLoad:

Adding the view and starting the camera
    // After setup is complete we add the module to the view of this view controller
    [self.view addSubview:self.scanView];
    //Start Camera:
    [self.scanView startCamera];

Final steps to configure and use the ID Plugin

The ID Delegate

In the MRZ Plugin of Anyline SDK, you will be provided the final results via delegate calls.

In case of the ID Plugin, the protocol is called ALIDPluginDelegate. This section describes the ALIDPluginDelegate callbacks in detail.

anylineIDScanPlugin:didFindResult:

This is the main callback method for the ID Plugin. It is called once a valid result has been found.

The callback returns the result as ALIDResult, which contains an ` object, the allCheckDigitsValid flag, as well as an image of the result.

Result Delegate
/*
 This is the main delegate method Anyline uses to report its results
 */
- (void)anylineIDScanPlugin:(ALIDScanPlugin *)anylineIDScanPlugin
              didFindResult:(ALIDResult *)scanResult {
    [self.drivingLicenseScanViewPlugin stopAndReturnError:nil];
    
    NSMutableString * result = [NSMutableString string];
    [result appendString:[NSString stringWithFormat:@"Document Number: %@\n", [scanResult.result documentNumber]]];
    [result appendString:[NSString stringWithFormat:@"Last Name: %@\n", [scanResult.result surNames]]];
    [result appendString:[NSString stringWithFormat:@"First Name: %@\n", [scanResult.result givenNames]]];
    [result appendString:[NSString stringWithFormat:@"Date of Birth: %@", [scanResult.result dayOfBirth]]];
    ;
   [super anylineDidFindResult:result barcodeResult:@"" image:scanResult.image scanPlugin:anylineIDScanPlugin viewPlugin:self.drivingLicenseScanViewPlugin completion:^{
        NSMutableArray <ALResultEntry*> *resultData = [[NSMutableArray alloc] init];

        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"Last Name" value:[scanResult.result surNames]]];
        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"First Name" value:[scanResult.result givenNames]]];
        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"Date of Birth" value:[scanResult.result dayOfBirth]]];
        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"Document Number" value:[scanResult.result documentNumber]]];
        
        //Display the result
        ALResultViewController *vc = [[ALResultViewController alloc] initWithResultData:resultData image:scanResult.image];
        [self.navigationController pushViewController:vc animated:YES];
    }];
}
  • ALIDResult scanResult
Field Type Nullable Description
result ALDrivingLicenseIdentification The detected result as an object of typ ALDrivingLicenseIdentification
image UIImage The image the result was found on. The image is cropped to the cutout
fullImage UIImage The full image the result was found on.
confidence NSInteger The confidence of the SDK in the detected result
Identification

The detected Driving License fields are grouped within an ALDrivingLicenseIdentification object.
The object contains the following fields:

documentNumber
Type Description Parameter Explanation
NSString The Number of the Document Document Number
surNames
Type Description Parameter Explanation
NSString The surname(s) of the Document holder Surname
givenNames
Type Description Parameter Explanation
NSString The first name(s) of the Document holder Given Names
dayOfBirth
Type Description Parameter Explanation
NSString The day of birth of the Document holder Birth Date
dayOfBirthDateObject
The following assumption are made: dayOfBirthDateObject will return 1900 century if the parsed returned dateOfBirth string is bigger then TODAY, otherwise it will have 2000 century.
Type Description Parameter Explanation
NSDate The day of birth of the Document holder parsed as a date object Birth Date
placeOfBirth
Type Description Parameter Explanation
NSString The place of birth of the Document holder Place of Birth
issuingDate
Type Description Parameter Explanation
NSString The issuing date of the Document holder Issuing Date
expirationDate
Type Description Parameter Explanation
NSString The expiration date of the Document holder Expiration Date
authority
Type Description Parameter Explanation
NSString The issuing authority of the Document holder Issuing Authority
drivingLicenseString
Type Description
NSString The full Driving License String including line breaks

New in version 3.13.0.

Enabling or Disabling the Reporting

The reporting of the (intermediate) results is turned off for this Plugin.

Starting Scanning

Hint

Use [scanView startCamera] within viewDidload before starting Anyline.

After everything is initialised, you can start the scanning process, by calling startAndReturnError: on the plugin.

It is advised to place this call in the viewDidAppear: lifecycle method of the UIViewController.

Starting the plugin
    NSError *error;
    BOOL success = [self.drivingLicenseScanViewPlugin startAndReturnError:&error];
    if( !success ) {
        // Something went wrong. The error object contains the error description
        NSAssert(success, @"Start Scanning Error: %@", error.debugDescription);
    }

Stop Scanning

To stop the scanning process, call stopAndReturnError: on the plugin.

To make sure the SDK is properly stopped upon leaving the Activity, make sure to place stopAndReturnError: in the viewWillDisappear: lifecycle method of the UIViewController.

Stopping the plugin
/*
 Cancel scanning to allow the module to clean up
 */
- (void)viewWillDisappear:(BOOL)animated {
    [self.drivingLicenseScanViewPlugin stopAndReturnError:nil];
}

Full Example Activity

Full MRZ iOS Example
#import "ALDrivingLicenseScanViewController.h"
#import "ALAppDemoLicenses.h"
#import "ALResultViewController.h"
#import <Anyline/Anyline.h>


// This is the license key for the examples project used to set up Aynline below
NSString * const kDrivingLicenseLicenseKey = kDemoAppLicenseKey;
@interface ALDrivingLicenseScanViewController ()<ALIDPluginDelegate, ALInfoDelegate>
// The Anyline module used to scan machine readable zones
@property (nonatomic, strong) ALIDScanViewPlugin *drivingLicenseScanViewPlugin;
@property (nonatomic, strong) ALIDScanPlugin *drivingLicenseScanPlugin;
@property (nullable, nonatomic, strong) ALScanView *scanView;

@end

@implementation ALDrivingLicenseScanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Set the background color to black to have a nicer transition
    self.view.backgroundColor = [UIColor blackColor];
    self.title = @"Driving License";
    
    // Initializing the module. Its a UIView subclass. We set the frame to fill the whole screen
    CGRect frame = [[UIScreen mainScreen] applicationFrame];
    frame = CGRectMake(frame.origin.x, frame.origin.y + self.navigationController.navigationBar.frame.size.height, frame.size.width, frame.size.height - self.navigationController.navigationBar.frame.size.height);
    
    ALDrivingLicenseConfig *drivingLicenseConfig = [[ALDrivingLicenseConfig alloc] init];
    
    NSError *error = nil;
    self.drivingLicenseScanPlugin = [[ALIDScanPlugin alloc] initWithPluginID:@"ModuleID" licenseKey:kDrivingLicenseLicenseKey delegate:self idConfig:drivingLicenseConfig error:&error];
    NSAssert(self.drivingLicenseScanPlugin, @"Setup Error: %@", error.debugDescription);
    [self.drivingLicenseScanPlugin addInfoDelegate:self];
    
    self.drivingLicenseScanViewPlugin = [[ALIDScanViewPlugin alloc] initWithScanPlugin:self.drivingLicenseScanPlugin];
    NSAssert(self.drivingLicenseScanViewPlugin, @"Setup Error: %@", error.debugDescription);
    
    self.scanView = [[ALScanView alloc] initWithFrame:frame scanViewPlugin:self.drivingLicenseScanViewPlugin];
    
    self.scanView.flashButtonConfig.flashAlignment = ALFlashAlignmentTopLeft;
    
    self.controllerType = ALScanHistoryDrivingLicense;
    
    // After setup is complete we add the module to the view of this view controller
    [self.view addSubview:self.scanView];
    //Start Camera:
    [self.scanView startCamera];
    
    [self.view sendSubviewToBack:self.scanView];
    [self startListeningForMotion];
}

/*
 This method will be called once the view controller and its subviews have appeared on screen
 */
-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    // We use this subroutine to start Anyline. The reason it has its own subroutine is
    // so that we can later use it to restart the scanning process.
    [self startAnyline];
}

/*
 Cancel scanning to allow the module to clean up
 */
- (void)viewWillDisappear:(BOOL)animated {
    [self.drivingLicenseScanViewPlugin stopAndReturnError:nil];
}

/*
 This method is used to tell Anyline to start scanning. It gets called in
 viewDidAppear to start scanning the moment the view appears. Once a result
 is found scanning will stop automatically (you can change this behaviour
 with cancelOnResult:). When the user dismisses self.identificationView this
 method will get called again.
 */
- (void)startAnyline {
    NSError *error;
    BOOL success = [self.drivingLicenseScanViewPlugin startAndReturnError:&error];
    if( !success ) {
        // Something went wrong. The error object contains the error description
        NSAssert(success, @"Start Scanning Error: %@", error.debugDescription);
    }
}


#pragma mark -- AnylineOCRModuleDelegate

/*
 This is the main delegate method Anyline uses to report its results
 */
- (void)anylineIDScanPlugin:(ALIDScanPlugin *)anylineIDScanPlugin
              didFindResult:(ALIDResult *)scanResult {
    [self.drivingLicenseScanViewPlugin stopAndReturnError:nil];
    
    NSMutableString * result = [NSMutableString string];
    [result appendString:[NSString stringWithFormat:@"Document Number: %@\n", [scanResult.result documentNumber]]];
    [result appendString:[NSString stringWithFormat:@"Last Name: %@\n", [scanResult.result surNames]]];
    [result appendString:[NSString stringWithFormat:@"First Name: %@\n", [scanResult.result givenNames]]];
    [result appendString:[NSString stringWithFormat:@"Date of Birth: %@", [scanResult.result dayOfBirth]]];
    ;
   [super anylineDidFindResult:result barcodeResult:@"" image:scanResult.image scanPlugin:anylineIDScanPlugin viewPlugin:self.drivingLicenseScanViewPlugin completion:^{
        NSMutableArray <ALResultEntry*> *resultData = [[NSMutableArray alloc] init];

        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"Last Name" value:[scanResult.result surNames]]];
        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"First Name" value:[scanResult.result givenNames]]];
        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"Date of Birth" value:[scanResult.result dayOfBirth]]];
        [resultData addObject:[[ALResultEntry alloc] initWithTitle:@"Document Number" value:[scanResult.result documentNumber]]];
        
        //Display the result
        ALResultViewController *vc = [[ALResultViewController alloc] initWithResultData:resultData image:scanResult.image];
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSError *error = nil;
    BOOL success = [self.drivingLicenseScanViewPlugin startAndReturnError:&error];
    
    NSAssert(success, @"We failed starting: %@",error.debugDescription);
}

@end