Skip to main content

AilaMRZScanObject

Object representing a scanned MRZ (Machine Readable Zone).

Declaration

@interface AilaMRZScanObject : AilaScanObject
@property (nonatomic) AilaCodeType type;
@property (nonatomic) NSString *data;
@property (nonatomic) NSString *rawData;
@end

Description

This object is returned as part of the scanCallback upon a successful MRZ scan. It extends AilaScanObject with an additional rawData property containing the unparsed MRZ string.

The first line of an MRZ is more prone to character recognition errors because it does not include a checksum. Although Aila applies redundancy checks to improve accuracy, we recommend that customers performing backend MRZ validation rely primarily on fields that include a checksum such as the passport number, date of birth, or date of expiry and use name fields only as secondary validation.

Properties

type

Always AilaCodeTypeMRZ for MRZ scans.

Type: AilaCodeType

data

Returns the parsed data from the MRZ in a JSON string.

Type: NSString / String

Example JSON structure:

{
"Surname": "ERIKSSON",
"Expiration Date": "2012-04-15",
"Optional Data": "ZE184226B",
"Document Number": "L898902C3",
"Sex": "F",
"Birth Date": "1974-08-12",
"Country Code": "UTO",
"Document Type": "P",
"Given Names": "ANNA MARIA",
"Nationality": "UTO"
}

Date Format: YYYY-MM-DD Document Type: "P" for passport, "ID" for ID cards

info

Given Names may be truncated in cases where this information exceeds the character limit of the MRZ string.

rawData

Returns the raw string from the MRZ.

Type: NSString / String

This is the unparsed MRZ string as read from the document.

Methods

typeDescription

Returns the descriptive text "MRZ".

Returns: NSString / String

Usage Example

config.mrzMode = AilaMRZModeOn;
config.scanCallback = ^(NSArray<AilaScanObject *> *results) {
for (AilaScanObject *scan in results) {
if ([scan isKindOfClass:[AilaMRZScanObject class]]) {
AilaMRZScanObject *mrzScan = (AilaMRZScanObject *)scan;

// Get parsed JSON data
NSString *jsonData = mrzScan.data;
NSData *data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *parsed = [NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];

NSString *documentNumber = parsed[@"Document Number"];
NSString *surname = parsed[@"Surname"];
NSLog(@"Passport: %@, Name: %@", documentNumber, surname);

// Get raw MRZ string
NSString *rawMRZ = mrzScan.rawData;
NSLog(@"Raw MRZ: %@", rawMRZ);
}
}
};

See Also