Skip to content

Using MyKad recognizer

juraskrlec edited this page Aug 23, 2017 · 1 revision

MyKad recognizer is responsible for scanning, decoding and parsing front side of Malaysian ID documents MyKads

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 MyKad recognizer, it's settings class PPMyKadRecognizerSettings, and result class PPMyKadRecognizerResult to obtain Driver's license information from the scanning results.

Back to "Getting started" guide.

Initializing the scanning of MyKad (Malysian ID) documents

Below is the sample source code which initializes the scanning for Malaysian ID documents.

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

// To specify we want to perform MyKad (Malysian ID document) recognition, initialize the MyKad recognizer settings
PPMyKadRecognizerSettings *mykadRecognizerSettings = [[PPMyKadRecognizerSettings alloc] init];

// Add MyKad Recognizer setting to a list of used recognizer settings
[settings.scanSettings addRecognizerSettings:mykadRecognizerSettings];

Retrieving results

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

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

- (void)scanningViewController:(UIViewController<PPScanningViewController> *)scanningViewController
              didOutputResults:(NSArray<PPRecognizerResult *> *)results {

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

    // first, pause scanning until we process all the results
    [scanningViewController pauseScanning];

    // Collect data from the result
    for (PPRecognizerResult* result in results) {

        // Check if result is MyKad result
        if ([result isKindOfClass:[PPMyKadRecognizerResult class]]) {

            // Cast result to PPMyKadRecognizerResult
            PPMyKadRecognizerResult *myKadResult = (PPMyKadRecognizerResult *)result;

            // For accessing owner full name, use property ownerFullName
            NSLog(@"Full name: %@", myKadResult.ownerFullName);

            // For accessing NRIC number, use property nricNumber
            NSLog(@"NRIC no.: %@", myKadResult.nricNumber);

            // For accessing owner address, use property ownerAddress
            NSLog(@"Address: %@", myKadResult.ownerAddress);

            // For accessing Birth date, use property ownerBirthDate
            NSLog(@"Birth date: %@", myKadResult.ownerBirthDate);

            // For accessing Religion, use property ownerReligion
            NSLog(@"Religion: %@", myKadResult.ownerReligion);

            // For accessing owner sex, use property ownerSex
            NSLog(@"Sex: %@", myKadResult.ownerSex);
        }
    };

    // either resume scanning, or dismiss Scanning View controller
    // [scanningViewController resumeScanningAndResetState:YES];
    [scanningViewController dismissViewControllerAnimated:YES completion:nil];
}
Clone this wiki locally