Posted on: Wednesday, 24 July 2019
This is a sample application for using MRZ Scanner, the main purpose is to serve as a guide for implementing and using the library. It contains examples of the scanner practical integration.
To skip this guide, go to the link below to be redirected to the downloading page.
https://mrzscanner.com/download
https://github.com/Realmrzscanner/MRZScanner-SampleApp-iOS
import MRZScannerSDK
class ScrollViewController : UIViewController, MRZScannerDelegate
Returns the scanner results for ScannerType.SCANNER_TYPE_MRZ, you can further on pick in whatever format you want them to be when assigning to a variable.
Returns the scanner results for ScannerType.SCANNER_TYPE_DOC_IMAGE_ID & SCANNER_TYPE_DOC_IMAGE_PASSPORT, returns a bitmap.
2. We start the scanner from the UIApplication's rootViewController as a child view. The Mrz Scanner type is set to "SCANNER_TYPE_MRZ", and set the maximum CPU cores. The function is called on a button click.
func startScanner()-> Void {
DispatchQueue.main.async {
let currentVC = self
self.mrzScannerController?.setMaxCPUCores(self.maxCoreSetVar)
self.mrzScannerController = MRZScannerController.init()
self.mrzScannerController!.delegate = self
currentVC.addChild(self.mrzScannerController!)
self.mrzScannerController?.setMaxCPUCores(self.maxCoreSetVar)
self.mrzScannerController?.setScannerType(MRZScannerType(rawValue:MRZScannerType.RawValue(0)))
self.mrzScannerController!.initUI(currentVC)
}
}
3. After a successful scan, the scan returns the scanned data and adds it to a text field for a display.
func successfulScan(withResult result: MRZResultDataModel!) {
if(result != nil){
self.mrzScannerController?.dismiss(animated: true, completion: nil)
surnameEditTxt.insertText(result.surnames_readable)
givenNameEditTxt.insertText(result.given_names_readable)
documentNumberEditTxt.insertText(result.document_type_readable)
issuingCountryEditTxt.insertText(result.est_issuing_date_readable)
nationalityEditTxt.insertText(result.nationality)
dateofBirthEditTxt.insertText(result.dob_readable)
sexEditTxt.insertText(result.sex)
estimatedIssuingDateEditTxt.insertText(result.est_issuing_date_readable)
expirationdateEditTxt.insertText(result.expiration_date_readable)
optionalvalueeditTxt.insertText(result.optionals_readable)
}
}
@IBAction func startScannerAction(_ sender: Any) {
startScanner()
}
4. With the successfulScan() method we have retrieved the data from our ID/Passport and filled in the fields, next we've added two views that will take the front and back Image of our document. For the following, we're calling for "SCANNER_TYPE_DOC_IMAGE_ID" and set is as our type scanner and called setIDActive to true so it enables the scanner to recognize ID.
func takeImageID()
{
MRZScannerController.setIDActive(true)
self.mrzScannerController?.setScannerType(MRZScannerType(rawValue:MRZScannerType.RawValue(1)))
}
5. We've already declared a global var that will take in the result from the delegate method successfulScanWithDocumentImage, and add it to display in our view.
func successfulDocumentScan(withImageResult resultImage: UIImage!) {
imageData = resultImage;
self.mrzScannerController!.dismiss(animated: true, completion:nil)
}