├── .gitignore ├── .npmignore ├── BlinkID ├── blinkid-react-native.podspec ├── index.js ├── overlaySettings.js ├── overlays │ └── blinkidOverlays.js ├── package.json ├── parser.js ├── react-native.config.js ├── recognizer.js ├── recognizers │ ├── blinkIdMultiSideRecognizer.js │ ├── blinkIdSingleSideRecognizer.js │ ├── documentFaceRecognizer.js │ ├── idBarcodeRecognizer.js │ ├── mrtdCombinedRecognizer.js │ ├── mrtdRecognizer.js │ ├── passportRecognizer.js │ ├── successFrameGrabberRecognizer.js │ ├── usdlCombinedRecognizer.js │ ├── usdlRecognizer.js │ └── visaRecognizer.js ├── src │ ├── android │ │ ├── .gitignore │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── microblink │ │ │ │ └── blinkid │ │ │ │ └── reactnative │ │ │ │ ├── BlinkIDReactPackage.java │ │ │ │ ├── MicroblinkModule.java │ │ │ │ ├── SerializationUtils.java │ │ │ │ ├── overlays │ │ │ │ ├── OverlaySettingsSerialization.java │ │ │ │ ├── OverlaySettingsSerializers.java │ │ │ │ └── serialization │ │ │ │ │ ├── BlinkIDOverlaySerializationUtils.java │ │ │ │ │ ├── BlinkIdOverlaySettingsSerialization.java │ │ │ │ │ ├── DocumentOverlaySettingsSerialization.java │ │ │ │ │ ├── DocumentVerificationOverlaySettingsSerialization.java │ │ │ │ │ └── OverlaySerializationUtils.java │ │ │ │ └── recognizers │ │ │ │ ├── RecognizerSerialization.java │ │ │ │ ├── RecognizerSerializers.java │ │ │ │ └── serialization │ │ │ │ ├── BlinkIDSerializationUtils.java │ │ │ │ ├── BlinkIdMultiSideRecognizerSerialization.java │ │ │ │ ├── BlinkIdSingleSideRecognizerSerialization.java │ │ │ │ ├── DocumentFaceRecognizerSerialization.java │ │ │ │ ├── IdBarcodeRecognizerSerialization.java │ │ │ │ ├── MrtdCombinedRecognizerSerialization.java │ │ │ │ ├── MrtdRecognizerSerialization.java │ │ │ │ ├── PassportRecognizerSerialization.java │ │ │ │ ├── SuccessFrameGrabberRecognizerSerialization.java │ │ │ │ ├── UsdlCombinedRecognizerSerialization.java │ │ │ │ ├── UsdlRecognizerSerialization.java │ │ │ │ └── VisaRecognizerSerialization.java │ │ │ └── res │ │ │ ├── layout │ │ │ └── mb_layout_camera_splash.xml │ │ │ └── raw │ │ │ └── beep.mp3 │ └── ios │ │ └── MicroblinkModule │ │ ├── MicroblinkModule.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ └── juraskrlec.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ └── MicroblinkModule │ │ ├── MBBlinkIDModule.h │ │ ├── MBBlinkIDModule.m │ │ ├── MBBlinkIDSerializationUtils.h │ │ ├── MBBlinkIDSerializationUtils.m │ │ ├── MBCommonSerializationUtils.h │ │ ├── MBCommonSerializationUtils.m │ │ ├── MBSerializationUtils.h │ │ ├── MBSerializationUtils.m │ │ ├── Overlays │ │ ├── MBOverlaySerializationUtils.h │ │ ├── MBOverlaySerializationUtils.m │ │ ├── MBOverlaySettingsSerializers.h │ │ ├── MBOverlaySettingsSerializers.m │ │ ├── MBOverlayVCCreator.h │ │ ├── MBOverlayViewControllerDelegate.h │ │ └── Serialization │ │ │ ├── MBBlinkIdOverlaySettingsSerialization.h │ │ │ ├── MBBlinkIdOverlaySettingsSerialization.m │ │ │ ├── MBDocumentOverlaySettingsSerialization.h │ │ │ ├── MBDocumentOverlaySettingsSerialization.m │ │ │ ├── MBDocumentVerificationOverlaySettingsSerialization.h │ │ │ └── MBDocumentVerificationOverlaySettingsSerialization.m │ │ └── Recognizers │ │ ├── MBRecognizerSerializers.h │ │ ├── MBRecognizerSerializers.m │ │ ├── MBRecognizerWrapper.h │ │ ├── MBRecognizerWrapper.m │ │ └── Wrappers │ │ ├── MBBlinkIdMultiSideRecognizerWrapper.h │ │ ├── MBBlinkIdMultiSideRecognizerWrapper.m │ │ ├── MBBlinkIdSingleSideRecognizerWrapper.h │ │ ├── MBBlinkIdSingleSideRecognizerWrapper.m │ │ ├── MBDocumentFaceRecognizerWrapper.h │ │ ├── MBDocumentFaceRecognizerWrapper.m │ │ ├── MBIdBarcodeRecognizerWrapper.h │ │ ├── MBIdBarcodeRecognizerWrapper.m │ │ ├── MBMrtdCombinedRecognizerWrapper.h │ │ ├── MBMrtdCombinedRecognizerWrapper.m │ │ ├── MBMrtdRecognizerWrapper.h │ │ ├── MBMrtdRecognizerWrapper.m │ │ ├── MBPassportRecognizerWrapper.h │ │ ├── MBPassportRecognizerWrapper.m │ │ ├── MBSuccessFrameGrabberRecognizerWrapper.h │ │ ├── MBSuccessFrameGrabberRecognizerWrapper.m │ │ ├── MBUsdlCombinedRecognizerWrapper.h │ │ ├── MBUsdlCombinedRecognizerWrapper.m │ │ ├── MBUsdlRecognizerWrapper.h │ │ ├── MBUsdlRecognizerWrapper.m │ │ ├── MBVisaRecognizerWrapper.h │ │ └── MBVisaRecognizerWrapper.m └── types.js ├── COPYRIGHT.md ├── README.md ├── Release notes.md ├── initReactNativeSampleApp.sh ├── publish.sh └── sample_files └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | 9 | xcuserdata 10 | xcshareddata 11 | 12 | node_modules 13 | .idea 14 | 15 | /Sample -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | initReactNativeDemoApp.sh 2 | /BlinkIDReactNative -------------------------------------------------------------------------------- /BlinkID/blinkid-react-native.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = package['name'] 7 | s.version = package['version'] 8 | s.summary = package['description'] 9 | 10 | s.authors = package['author'] 11 | s.homepage = package['homepage'] 12 | s.license = package['license'] 13 | s.platform = :ios, "13.0" 14 | 15 | s.source = { :git => "https://github.com/BlinkID/blinkid-react-native.git", :tag => "v#{s.version}" } 16 | s.source_files = "src/ios", "src/ios/**/*.{h,m}" 17 | s.header_dir = "blinkid-react-native" 18 | 19 | s.dependency 'React' 20 | s.dependency 'PPBlinkID', '~> 6.13.0' 21 | 22 | s.frameworks = 'UIKit' 23 | end 24 | -------------------------------------------------------------------------------- /BlinkID/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Platform, NativeModules } from 'react-native'; 4 | 5 | import { RecognizerResultState } from './recognizer' 6 | 7 | const BlinkIDNative = Platform.select({ 8 | ios: NativeModules.BlinkIDIos, 9 | android: NativeModules.BlinkIDAndroid 10 | }) 11 | 12 | /** 13 | * This exposes the appropriate native BlinkID module module as a JS module, based on 14 | * detected platform: Android or iOS. This has functions: 15 | * -> 'scanWithCamera' which takes the following parameters: 16 | * 1. Object overlaySettings: instance of OverlaySettings, contains settings for desired camera overlay 17 | * 2. RecognizerCollection recognizerCollection: object containing recognizers to use for scanning 18 | * 3. String license: BlinkID base64 license key bound to application ID for Android or iOS. To obtain 19 | * valid license key, please visit http://microblink.com/login or 20 | * contact us at http://help.microblink.com 21 | * 22 | * OR 23 | * 24 | * Object license: containing: 25 | * - mandatory parameter 'licenseKey': base64 license key bound to application ID 26 | * for Android or iOS. To obtain valid license key, please visit 27 | * http://microblink.com/login or contact us at http://help.microblink.com 28 | * - optioanl parameter 'licensee' when license for multiple apps is used 29 | * - optional flag 'showTrialLicenseKeyWarning' which indicates 30 | * whether warning for trial license key will be shown 31 | * in format 32 | * { 33 | * licenseKey: '', 34 | * licensee: String, 35 | * showTrialLicenseKeyWarning: Boolean 36 | * } 37 | * 38 | * -> 'scanWithDirectApi' takes the following parameters: 39 | * 1. RecognizerCollection recognizerCollection: object containing recognizers to use for scanning 40 | * 2. String frontImage: a Base64 format string that represents the front image of the document that will be used for processing with DirectAPI 41 | * 3. String backImage: a Base64 format string that represents the back image of the document that will be used for processing with DirectAPI 42 | * - backImage parameter is optional with the BlinkIdSingleSide recognizer, as only one side of the document is required. Pass 'null' or an empty string "" for this parameter in this case 43 | * 4. String license: BlinkID base64 license key bound to application ID for Android or iOS. To obtain 44 | * valid license key, please visit http://microblink.com/login or 45 | * contact us at http://help.microblink.com 46 | * 47 | * OR 48 | * 49 | * Object license: containing: 50 | * - mandatory parameter 'licenseKey': base64 license key bound to application ID 51 | * for Android or iOS. To obtain valid license key, please visit 52 | * http://microblink.com/login or contact us at http://help.microblink.com 53 | * - optioanl parameter 'licensee' when license for multiple apps is used 54 | * - optional flag 'showTrialLicenseKeyWarning' which indicates 55 | * whether warning for trial license key will be shown 56 | * in format 57 | * { 58 | * licenseKey: '', 59 | * licensee: String, 60 | * showTrialLicenseKeyWarning: Boolean 61 | * } 62 | */ 63 | class BlinkIDWrapper { 64 | async scanWithCamera(overlaySettings, recognizerCollection, license) { 65 | try { 66 | var licenseObject = license; 67 | if (typeof license === 'string' || license instanceof String) { 68 | licenseObject = { licenseKey: license }; 69 | } 70 | const nativeResults = await BlinkIDNative.scanWithCamera(overlaySettings, recognizerCollection, licenseObject); 71 | if (nativeResults.length != recognizerCollection.recognizerArray.length) { 72 | console.log("INTERNAL ERROR: native plugin returned wrong number of results!"); 73 | return []; 74 | } else { 75 | let results = []; 76 | for (let i = 0; i < nativeResults.length; ++i) { 77 | // native plugin must ensure types match 78 | // recognizerCollection.recognizerArray[i].result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]); 79 | 80 | // unlike Cordova, ReactNative does not allow mutation of user-provided recognizers, so we need to 81 | // return results and let user handle them manually. 82 | let result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]); 83 | if (result.resultState != RecognizerResultState.empty) { 84 | results.push(result); 85 | } 86 | } 87 | return results; 88 | } 89 | } catch (error) { 90 | console.log(error); 91 | return []; 92 | } 93 | } 94 | 95 | async scanWithDirectApi(recognizerCollection, frontImage, backImage, license) { 96 | try { 97 | var licenseObject = license; 98 | if (typeof license === 'string' || license instanceof String) { 99 | licenseObject = { licenseKey: license }; 100 | } 101 | 102 | var frontImageObject = frontImage; 103 | if (typeof frontImage === 'string' || frontImage instanceof String) { 104 | frontImageObject = { frontImage: frontImage }; 105 | } 106 | 107 | var backImageObject = backImage; 108 | if (typeof backImage === 'string' || backImage instanceof String) { 109 | backImageObject = { backImage: backImage }; 110 | } 111 | 112 | const nativeResults = await BlinkIDNative.scanWithDirectApi(recognizerCollection, frontImageObject, backImageObject, licenseObject); 113 | if (nativeResults.length != recognizerCollection.recognizerArray.length) { 114 | console.log("INTERNAL ERROR: native plugin returned wrong number of results!"); 115 | return []; 116 | } else { 117 | let results = []; 118 | for (let i = 0; i < nativeResults.length; ++i) { 119 | // native plugin must ensure types match 120 | // recognizerCollection.recognizerArray[i].result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]); 121 | 122 | // unlike Cordova, ReactNative does not allow mutation of user-provided recognizers, so we need to 123 | // return results and let user handle them manually. 124 | let result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]); 125 | if (result.resultState != RecognizerResultState.empty) { 126 | results.push(result); 127 | } 128 | } 129 | return results; 130 | } 131 | } catch (error) { 132 | console.log(error); 133 | return []; 134 | } 135 | } 136 | } 137 | 138 | export var BlinkID = new BlinkIDWrapper(); 139 | 140 | import { Recognizer } from './recognizer' 141 | 142 | /** 143 | * Represents a collection of recognizer objects. 144 | */ 145 | export class RecognizerCollection { 146 | /** 147 | * 148 | * @param recognizerArray Array of recognizer objects that will be used for recognition. Must not be empty! 149 | */ 150 | constructor(recognizerArray) { 151 | /** Array of recognizer objects that will be used for recognition */ 152 | this.recognizerArray = recognizerArray; 153 | /** 154 | * Whether or not it is allowed for multiple recognizers to process the same image. 155 | * If not, then first recognizer that will be successful in processing the image will 156 | * end the processing chain and other recognizers will not get the chance to process 157 | * that image. 158 | */ 159 | this.allowMultipleResults = false; 160 | /** Number of miliseconds after first non-empty result becomes available to end scanning with a timeout */ 161 | this.milisecondsBeforeTimeout = 0; 162 | 163 | if (!(this.recognizerArray instanceof Array)) { 164 | throw new Error("recognizerArray must be array of Recognizer objects!"); 165 | } 166 | // ensure every element in array is Recognizer 167 | for (var i = 0; i < this.recognizerArray.length; ++i) { 168 | if (!(this.recognizerArray[i] instanceof Recognizer )) { 169 | throw new Error( "Each element in recognizerArray must be instance of Recognizer" ); 170 | } 171 | } 172 | } 173 | } 174 | 175 | export { RecognizerResultState } from './recognizer' 176 | export * from './types' 177 | 178 | // export overlays that can be used 179 | export * from './overlays/blinkidOverlays' 180 | 181 | // export recognizers that can be used and their results 182 | export * from './recognizers/successFrameGrabberRecognizer' 183 | export * from './recognizers/blinkIdMultiSideRecognizer' 184 | export * from './recognizers/blinkIdSingleSideRecognizer' 185 | export * from './recognizers/documentFaceRecognizer' 186 | export * from './recognizers/idBarcodeRecognizer' 187 | export * from './recognizers/mrtdCombinedRecognizer' 188 | export * from './recognizers/mrtdRecognizer' 189 | export * from './recognizers/passportRecognizer' 190 | export * from './recognizers/visaRecognizer' 191 | export * from './recognizers/usdlRecognizer' 192 | export * from './recognizers/usdlCombinedRecognizer' 193 | -------------------------------------------------------------------------------- /BlinkID/overlaySettings.js: -------------------------------------------------------------------------------- 1 | /** Base class for all overlay settings objects */ 2 | export class OverlaySettings { 3 | constructor(overlaySettingsType) { 4 | /** type of the overlay settings object */ 5 | this.overlaySettingsType = overlaySettingsType; 6 | /** whether front camera should be used instead of the default camera */ 7 | this.useFrontCamera = false; 8 | /** whether beep sound will be played on successful scan */ 9 | this.enableBeep = false; 10 | /** (optional) if default overlay contains textual information, text will be localized to this language. Otherwise device langauge will be used */ 11 | /** example: "en" */ 12 | this.language = null; 13 | /** (optional) to be used with language variable, it defines the country locale */ 14 | /** example: "US" to use "en_US" on Android and en-US on iOS */ 15 | this.country = null; 16 | } 17 | } -------------------------------------------------------------------------------- /BlinkID/overlays/blinkidOverlays.js: -------------------------------------------------------------------------------- 1 | import { OverlaySettings } from '../overlaySettings' 2 | import { AndroidCameraResolutionPreset, 3 | iOSCameraResolutionPreset 4 | } from '../types' 5 | /** 6 | * Class for setting up document overlay. 7 | * Document overlay is best suited for recognizers that perform ID document scanning. 8 | */ 9 | export class DocumentOverlaySettings extends OverlaySettings { 10 | constructor() { 11 | super('DocumentOverlaySettings'); 12 | } 13 | } 14 | 15 | /** 16 | * Class for setting up BlinkId overlay. 17 | * BlinkId overlay is best suited for recognizers that perform ID document scanning. 18 | */ 19 | export class BlinkIdOverlaySettings extends OverlaySettings { 20 | constructor() { 21 | super('BlinkIdOverlaySettings'); 22 | /** 23 | * String: message that is shown while scanning first side of the document. 24 | * If null, default value will be used. 25 | */ 26 | this.firstSideInstructionsText = null; 27 | /** 28 | * String: instructions to flip document, shown when scanning of the first side is done, before scanning the second 29 | * side of the document. 30 | * If null, default value will be used. 31 | */ 32 | this.flipInstructions = null; 33 | /** 34 | * String: instructions for the user to move the document closer. 35 | * If null, default value will be used. 36 | */ 37 | this.errorMoveCloser = null; 38 | /** 39 | * String: instructions for the user to move the document farther. 40 | * If null, default value will be used. 41 | */ 42 | this.errorMoveFarther = null; 43 | /** 44 | * String: title of the dialog, which is shown when scanned document sides are not from the same document. 45 | * If null, default value will be used. 46 | */ 47 | this.sidesNotMatchingTitle = null; 48 | /** 49 | * String: message inside dialog, which is shown when scanned document sides are not from the same document. 50 | * If null, default value will be used. 51 | */ 52 | this.sidesNotMatchingMessage = null; 53 | /** 54 | * String: title of the dialog, which is shown when unsupported document is scanned. 55 | * If null, default value will be used. 56 | */ 57 | this.unsupportedDocumentTitle = null; 58 | /** 59 | * String: message inside dialog, which is shown when unsupported document is scanned. 60 | * If null, default value will be used. 61 | */ 62 | this.unsupportedDocumentMessage = null; 63 | /** 64 | * String: title of the dialog, which is shown on timeout when scanning is stuck on the back document side. 65 | * If null, default value will be used. 66 | */ 67 | this.recognitionTimeoutTitle = null; 68 | /** 69 | * String: message inside dialog, which is shown on timeout when scanning is stuck on the back document side. 70 | * If null, default value will be used. 71 | */ 72 | this.recognitionTimeoutMessage = null; 73 | /** 74 | * String: text of the "retry" button inside dialog, which is shown on timeout when scanning is stuck on the back 75 | * document side. 76 | */ 77 | this.retryButtonText = null; 78 | 79 | /** 80 | * If true, BlinkIdCombinedRecognizer will check if sides do match when scanning is finished 81 | * Default: true 82 | */ 83 | this.requireDocumentSidesDataMatch = true; 84 | 85 | /** 86 | * If default overlay contains textual information, text will be localized to this language. Otherwise device langauge will be used 87 | * 88 | * example: "en" 89 | */ 90 | this.language = null; 91 | 92 | /** 93 | * Used with language variable, it defines the country locale 94 | * 95 | * example: "US" to use "en_US" on Android and en-US on iOS 96 | */ 97 | this.country = null; 98 | 99 | /** 100 | * Defines whether Document Not Supported dialog will be displayed in UI. 101 | * 102 | * Default: true 103 | */ 104 | this.showNotSupportedDialog = true; 105 | 106 | /** 107 | * Defines whether glare warning will be displayed when user turn on a flashlight 108 | * 109 | * Default: true 110 | */ 111 | this.showFlashlightWarning = true; 112 | 113 | /** 114 | * Option to configure missing mandatory fields feedback during scanning. If disabled, general message is presented. 115 | * 116 | * Default: true 117 | */ 118 | this.showMandatoryFieldsMissing = true; 119 | 120 | /** 121 | * Option to configure back side scanning timeout. 122 | * 123 | * Default: 17000 124 | */ 125 | this.backSideScanningTimeoutMilliseconds = 17000; 126 | 127 | /** 128 | * Message that is shown while scanning the barcode. 129 | * If null, default value will be used. 130 | */ 131 | this.scanBarcodeText = null; 132 | 133 | /** 134 | * Instructions for the user to move the document from the edge. 135 | * If null, default value will be used. 136 | */ 137 | this.errorDocumentTooCloseToEdge = null; 138 | 139 | /** 140 | * String: title of the dialog which is shown when the data on the document is not matching. 141 | * If null, default value will be used. 142 | */ 143 | this.showOnboardingInfo = true; 144 | 145 | /** 146 | * Defines whether introduction dialog is turned on by default. 147 | * 148 | * Default: false 149 | */ 150 | this.showIntroductionDialog = false; 151 | 152 | /** 153 | * Option to configure onboarding button tooltip delay time. 154 | * 155 | * Default: 12000 156 | */ 157 | this.onboardingButtonTooltipDelay = 12000; 158 | 159 | /** 160 | * Defines whether torch button used for turning the flashlight on and off is shown on the screen during the scanning session. 161 | * 162 | * Default: true 163 | */ 164 | this.showTorchButton = true; 165 | 166 | /** 167 | * Defines whether exit (cancel) button used for cancelling the scan is shown on the screen during the scanning session. 168 | * 169 | * Default: true 170 | */ 171 | this.showCancelButton = true; 172 | 173 | /** 174 | * String: instructions for the user when blur has been detected on the document. 175 | * If null, default value will be used. 176 | */ 177 | this.errorBlurDetected = null; 178 | 179 | /** 180 | * String: instructions for the user when glare has been detected on the document. 181 | * If null, default value will be used. 182 | */ 183 | this.errorGlareDetected = null; 184 | 185 | /** 186 | * Defines possible Android device camera video resolution preset. 187 | * 188 | * Default: PresetDefault 189 | */ 190 | this.androidCameraResolutionPreset = AndroidCameraResolutionPreset.PresetDefault; 191 | 192 | /** 193 | * Defines possible iOS device camera video resolution preset. 194 | * 195 | * Default: PresetOptimal 196 | */ 197 | this.iosCameraResolutionPreset = iOSCameraResolutionPreset.PresetOptimal; 198 | 199 | /** 200 | * Option to set whether legacy camera API should be used even on Lollipop devices that support newer Camera2 API. 201 | * WARNING: This setting should only be used if the new Camera2 API is not working on the device. This setting should not be applied on all devices. 202 | * Default: false 203 | */ 204 | this.enableAndroidLegacyCameraApi = false; 205 | 206 | /** 207 | * String: Instructions to scan the passport, shown when scanning of the first side is done, before 208 | * scanning the second side of the document. 209 | * 210 | * If null, default value will be used. 211 | */ 212 | this.topPageInstructions = null; 213 | 214 | /** 215 | * String: Instructions to scan the passport, shown when scanning of the first side is done, before scanning the second 216 | * side of the document. 217 | * 218 | * If null, default value will be used. 219 | */ 220 | this.leftPageInstructions = null; 221 | 222 | /** 223 | * String: Instructions to scan the passport, shown when scanning of the first side is done, before scanning the second 224 | * side of the document. 225 | * 226 | * If null, default value will be used. 227 | */ 228 | this.rightPageInstructions = null; 229 | 230 | /** 231 | * String: Instructions to scan the passport, shown when scanning of the first side is done, before scanning the second 232 | * side of the document. 233 | * 234 | * If null, default value will be used. 235 | */ 236 | this.turnTopPageInstructions = null; 237 | 238 | /** 239 | * String: Instructions to scan the passport, shown when scanning of the first side is done, before scanning the second 240 | * side of the document. 241 | * 242 | * If null, default value will be used. 243 | */ 244 | this.turnLeftPageInstructions = null; 245 | 246 | /** 247 | * String: Instructions to scan the passport, shown when scanning of the first side is done, before scanning the second 248 | * side of the document. 249 | * 250 | * If null, default value will be used. 251 | */ 252 | this.turnRightPageInstructions = null; 253 | 254 | /** 255 | * String: Instructions for the user when wrong side of passport is being scanned. 256 | * 257 | * If null, default value will be used. 258 | */ 259 | this.errorScanningWrongPageTop = null; 260 | 261 | /** 262 | * String: Instructions for the user when wrong side of passport is being scanned. 263 | * 264 | * If null, default value will be used. 265 | */ 266 | this.errorScanningWrongPageLeft = null; 267 | 268 | /** 269 | * String: Instructions for the user when wrong side of passport is being scanned. 270 | * 271 | * If null, default value will be used. 272 | */ 273 | this.errorScanningWrongPageRight = null; 274 | } 275 | } 276 | 277 | /** 278 | * Class for setting up document verification overlay. 279 | * Document verification overlay is best suited for combined recognizers - recognizer that perform scanning of both sides of ID documents. 280 | */ 281 | export class DocumentVerificationOverlaySettings extends OverlaySettings { 282 | constructor() { 283 | super('DocumentVerificationOverlaySettings'); 284 | /** 285 | * String: splash message that is shown before scanning the first side of the document, while starting camera. 286 | * If null, default value will be used. 287 | */ 288 | this.firstSideSplashMessage = null; 289 | /** 290 | * String: splash message that is shown before scanning the second side of the document, while starting camera. 291 | * If null, default value will be used. 292 | */ 293 | this.secondSideSplashMessage = null; 294 | /** 295 | * String: splash message that is shown after scanning the document. 296 | * If null, default value will be used. 297 | */ 298 | this.scanningDoneSplashMessage = null; 299 | /** 300 | * String: user instructions that are shown above camera preview while the first side of the 301 | * document is being scanned. 302 | * If null, default value will be used. 303 | */ 304 | this.firstSideInstructions = null; 305 | /** 306 | * String: user instructions that are shown above camera preview while the second side of the 307 | * document is being scanned. 308 | * If null, default value will be used. 309 | */ 310 | this.secondSideInstructions = null; 311 | /** 312 | * String: glare message that is shown if glare was detected while scanning document. 313 | * If null, default value will be used. 314 | */ 315 | this.glareMessage = null; 316 | } 317 | } 318 | -------------------------------------------------------------------------------- /BlinkID/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blinkid-react-native", 3 | "version": "6.13.1", 4 | "description": "A small and powerful ID card scanning library. Powered by Microblink (www.microblink.com).", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/BlinkID/blinkid-react-native.git" 9 | }, 10 | "keywords": [ 11 | "scan", 12 | "id", 13 | "scanner", 14 | "identity", 15 | "ID", 16 | "passport", 17 | "licence", 18 | "sdk", 19 | "ocr", 20 | "USDL", 21 | "PDF417", 22 | "MRZ", 23 | "MRTD", 24 | "barcode", 25 | "DL", 26 | "card", 27 | "document", 28 | "microblink", 29 | "react-native", 30 | "blinkid", 31 | "ID", 32 | "ios", 33 | "android" 34 | ], 35 | "author": "Microblink", 36 | "license": "MIT", 37 | "homepage": "https://github.com/BlinkID/blinkid-react-native", 38 | "bugs": { 39 | "url": "https://github.com/BlinkID/blinkid-react-native/issues" 40 | }, 41 | "rnpm": { 42 | "android": { 43 | "sourceDir": "./src/android" 44 | }, 45 | "ios": { 46 | "sourceDir": "./src/ios" 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /BlinkID/parser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Base class for all parsers. 3 | * Parser is object that performs specific parsing 4 | * and updates its result with data extracted from the image. 5 | */ 6 | export class Parser { 7 | constructor(parserType) { 8 | /** Type of parser */ 9 | this.parserType = parserType; 10 | /** Defines/returns whether the parser configured with this parser settings object will be required or optional. */ 11 | this.required = true; 12 | } 13 | } 14 | 15 | /** 16 | * Possible states of the Parser's result 17 | */ 18 | export const ParserResultState = Object.freeze( 19 | { 20 | /** Parser result is empty */ 21 | empty : 0, 22 | /** Parser result contains some values, but is incomplete or it contains all values, but some are uncertain */ 23 | uncertain : 1, 24 | /** Parser result contains all required values */ 25 | valid : 2 26 | } 27 | ); 28 | 29 | /** 30 | * Base class for all parsers's result objects. 31 | * Parser result contains data extracted from the image. 32 | */ 33 | export class ParserResult { 34 | constructor(resultState) { 35 | /** 36 | * State of the result. It is always one of the values represented by ParserResultState enum 37 | */ 38 | this.resultState = resultState; 39 | } 40 | } -------------------------------------------------------------------------------- /BlinkID/react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependency: { 3 | platforms: { 4 | android: { 5 | sourceDir: './src/android' 6 | } 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /BlinkID/recognizer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Base class for all recognizers. 3 | * Recognizer is object that performs recognition of image 4 | * and updates its result with data extracted from the image. 5 | */ 6 | export class Recognizer { 7 | constructor(recognizerType) { 8 | /** Type of recognizer */ 9 | this.recognizerType = recognizerType; 10 | } 11 | } 12 | 13 | /** 14 | * Possible states of the Recognizer's result 15 | */ 16 | export const RecognizerResultState = Object.freeze( 17 | { 18 | /** Recognizer result is empty */ 19 | empty : 0, 20 | /** Recognizer result contains some values, but is incomplete or it contains all values, but some are uncertain */ 21 | uncertain : 1, 22 | /** Recognizer result contains all required values */ 23 | valid : 2, 24 | stageValid: 3 25 | } 26 | ); 27 | 28 | /** 29 | * Base class for all recognizer's result objects. 30 | * Recognizer result contains data extracted from the image. 31 | */ 32 | export class RecognizerResult { 33 | constructor(resultState) { 34 | /** 35 | * State of the result. It is always one of the values represented by RecognizerResultState enum 36 | */ 37 | this.resultState = resultState; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BlinkID/recognizers/documentFaceRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | Date, 4 | Point, 5 | Quadrilateral, 6 | MrtdDocumentType, 7 | MrzResult, 8 | DocumentFaceDetectorType, 9 | Country, 10 | Region, 11 | Type, 12 | DocumentImageColorStatus, 13 | DocumentImageMoireStatus, 14 | AnonymizationMode, 15 | RecognitionModeFilter, 16 | StrictnessLevel, 17 | ClassFilter, 18 | 19 | 20 | ImageExtensionFactors, 21 | DataMatchResult, 22 | } from '../types' 23 | 24 | /** 25 | * Result object for DocumentFaceRecognizer. 26 | */ 27 | export class DocumentFaceRecognizerResult extends RecognizerResult { 28 | constructor(nativeResult) { 29 | super(nativeResult.resultState); 30 | 31 | /** 32 | * Quadrangle represeting corner points of the document within the input image. 33 | */ 34 | this.documentLocation = nativeResult.documentLocation != null ? new Quadrilateral(nativeResult.documentLocation) : null; 35 | 36 | /** 37 | * face image from the document if enabled with returnFaceImage property. 38 | */ 39 | this.faceImage = nativeResult.faceImage; 40 | 41 | /** 42 | * Quadrangle represeting corner points of the face image within the input image. 43 | */ 44 | this.faceLocation = nativeResult.faceLocation != null ? new Quadrilateral(nativeResult.faceLocation) : null; 45 | 46 | /** 47 | * full document image if enabled with returnFullDocumentImage property. 48 | */ 49 | this.fullDocumentImage = nativeResult.fullDocumentImage; 50 | 51 | } 52 | } 53 | 54 | /** 55 | * Class for configuring Document Face Recognizer Recognizer. 56 | * 57 | * Document Face Recognizer recognizer is used for scanning documents containing face images. 58 | */ 59 | export class DocumentFaceRecognizer extends Recognizer { 60 | constructor() { 61 | super('DocumentFaceRecognizer'); 62 | 63 | /** 64 | * Type of docment this recognizer will scan. 65 | * 66 | * 67 | */ 68 | this.detectorType = DocumentFaceDetectorType.TD1; 69 | 70 | /** 71 | * Property for setting DPI for face images 72 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 73 | * 74 | * 75 | */ 76 | this.faceImageDpi = 250; 77 | 78 | /** 79 | * Property for setting DPI for full document images 80 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 81 | * 82 | * 83 | */ 84 | this.fullDocumentImageDpi = 250; 85 | 86 | /** 87 | * Image extension factors for full document image. 88 | * 89 | * @see ImageExtensionFactors 90 | * 91 | */ 92 | this.fullDocumentImageExtensionFactors = new ImageExtensionFactors(); 93 | 94 | /** 95 | * Defines how many times the same document should be detected before the detector 96 | * returns this document as a result of the deteciton 97 | * 98 | * Higher number means more reliable detection, but slower processing 99 | * 100 | * 101 | */ 102 | this.numStableDetectionsThreshold = 6; 103 | 104 | /** 105 | * Sets whether face image from ID card should be extracted 106 | * 107 | * 108 | */ 109 | this.returnFaceImage = false; 110 | 111 | /** 112 | * Sets whether full document image of ID card should be extracted. 113 | * 114 | * 115 | */ 116 | this.returnFullDocumentImage = false; 117 | 118 | this.createResultFromNative = function (nativeResult) { return new DocumentFaceRecognizerResult(nativeResult); } 119 | } 120 | } -------------------------------------------------------------------------------- /BlinkID/recognizers/idBarcodeRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | Date, 4 | Point, 5 | Quadrilateral, 6 | MrtdDocumentType, 7 | MrzResult, 8 | DocumentFaceDetectorType, 9 | Country, 10 | Region, 11 | Type, 12 | DocumentImageColorStatus, 13 | DocumentImageMoireStatus, 14 | AnonymizationMode, 15 | RecognitionModeFilter, 16 | StrictnessLevel, 17 | ClassFilter, 18 | 19 | 20 | ImageExtensionFactors, 21 | DataMatchResult, 22 | } from '../types' 23 | 24 | /** 25 | * Result object for IdBarcodeRecognizer. 26 | */ 27 | export class IdBarcodeRecognizerResult extends RecognizerResult { 28 | constructor(nativeResult) { 29 | super(nativeResult.resultState); 30 | 31 | /** 32 | * The additional name information of the document owner. 33 | */ 34 | this.additionalNameInformation = nativeResult.additionalNameInformation; 35 | 36 | /** 37 | * The address of the document owner. 38 | */ 39 | this.address = nativeResult.address; 40 | 41 | /** 42 | * The current age of the document owner in years. It is calculated difference 43 | * between now and date of birth. Now is current time on the device. 44 | * @return current age of the document owner in years or -1 if date of birth is unknown. 45 | */ 46 | this.age = nativeResult.age; 47 | 48 | /** 49 | * Type of the barcode scanned 50 | * 51 | * @return Type of the barcode 52 | */ 53 | this.barcodeType = nativeResult.barcodeType; 54 | 55 | /** 56 | * The city address portion of the document owner. 57 | */ 58 | this.city = nativeResult.city; 59 | 60 | /** 61 | * The date of birth of the document owner. 62 | */ 63 | this.dateOfBirth = nativeResult.dateOfBirth != null ? new Date(nativeResult.dateOfBirth) : null; 64 | 65 | /** 66 | * The date of expiry of the document. 67 | */ 68 | this.dateOfExpiry = nativeResult.dateOfExpiry != null ? new Date(nativeResult.dateOfExpiry) : null; 69 | 70 | /** 71 | * The date of issue of the document. 72 | */ 73 | this.dateOfIssue = nativeResult.dateOfIssue != null ? new Date(nativeResult.dateOfIssue) : null; 74 | 75 | /** 76 | * The additional number of the document. 77 | */ 78 | this.documentAdditionalNumber = nativeResult.documentAdditionalNumber; 79 | 80 | /** 81 | * The document number. 82 | */ 83 | this.documentNumber = nativeResult.documentNumber; 84 | 85 | /** 86 | * The document type deduced from the recognized barcode 87 | * 88 | * @return Type of the document 89 | */ 90 | this.documentType = nativeResult.documentType; 91 | 92 | /** 93 | * The employer of the document owner. 94 | */ 95 | this.employer = nativeResult.employer; 96 | 97 | /** 98 | * The additional privileges granted to the driver license owner. 99 | */ 100 | this.endorsements = nativeResult.endorsements; 101 | 102 | /** 103 | * Checks whether the document has expired or not by comparing the current 104 | * time on the device with the date of expiry. 105 | * 106 | * @return true if the document has expired, false in following cases: 107 | * document does not expire (date of expiry is permanent) 108 | * date of expiry has passed 109 | * date of expiry is unknown and it is not permanent 110 | */ 111 | this.expired = nativeResult.expired; 112 | 113 | /** 114 | * Document specific extended elements that contain all barcode fields in their original form. 115 | * 116 | * Currently this is only filled for AAMVACompliant documents. 117 | */ 118 | this.extendedElements = nativeResult.extendedElements; 119 | 120 | /** 121 | * The first name of the document owner. 122 | */ 123 | this.firstName = nativeResult.firstName; 124 | 125 | /** 126 | * The full name of the document owner. 127 | */ 128 | this.fullName = nativeResult.fullName; 129 | 130 | /** 131 | * The issuing authority of the document. 132 | */ 133 | this.issuingAuthority = nativeResult.issuingAuthority; 134 | 135 | /** 136 | * The jurisdiction code address portion of the document owner. 137 | */ 138 | this.jurisdiction = nativeResult.jurisdiction; 139 | 140 | /** 141 | * The last name of the document owner. 142 | */ 143 | this.lastName = nativeResult.lastName; 144 | 145 | /** 146 | * The marital status of the document owner. 147 | */ 148 | this.maritalStatus = nativeResult.maritalStatus; 149 | 150 | /** 151 | * The middle name of the document owner. 152 | */ 153 | this.middleName = nativeResult.middleName; 154 | 155 | /** 156 | * The nationality of the documet owner. 157 | */ 158 | this.nationality = nativeResult.nationality; 159 | 160 | /** 161 | * The personal identification number. 162 | */ 163 | this.personalIdNumber = nativeResult.personalIdNumber; 164 | 165 | /** 166 | * The place of birth of the document owner. 167 | */ 168 | this.placeOfBirth = nativeResult.placeOfBirth; 169 | 170 | /** 171 | * The postal code address portion of the document owner. 172 | */ 173 | this.postalCode = nativeResult.postalCode; 174 | 175 | /** 176 | * The profession of the document owner. 177 | */ 178 | this.profession = nativeResult.profession; 179 | 180 | /** 181 | * The race of the document owner. 182 | */ 183 | this.race = nativeResult.race; 184 | 185 | /** 186 | * Byte array with result of the scan 187 | */ 188 | this.rawData = nativeResult.rawData; 189 | 190 | /** 191 | * The religion of the document owner. 192 | */ 193 | this.religion = nativeResult.religion; 194 | 195 | /** 196 | * The residential stauts of the document owner. 197 | */ 198 | this.residentialStatus = nativeResult.residentialStatus; 199 | 200 | /** 201 | * The restrictions to driving privileges for the driver license owner. 202 | */ 203 | this.restrictions = nativeResult.restrictions; 204 | 205 | /** 206 | * The sex of the document owner. 207 | */ 208 | this.sex = nativeResult.sex; 209 | 210 | /** 211 | * The street address portion of the document owner. 212 | */ 213 | this.street = nativeResult.street; 214 | 215 | /** 216 | * Retrieves string content of scanned data 217 | */ 218 | this.stringData = nativeResult.stringData; 219 | 220 | /** 221 | * Flag indicating uncertain scanning data 222 | * E.g obtained from damaged barcode. 223 | */ 224 | this.uncertain = nativeResult.uncertain; 225 | 226 | /** 227 | * The type of vehicle the driver license owner has privilege to drive. 228 | */ 229 | this.vehicleClass = nativeResult.vehicleClass; 230 | 231 | } 232 | } 233 | 234 | /** 235 | * The ID Barcode Recognizer is used for scanning ID Barcode. 236 | */ 237 | export class IdBarcodeRecognizer extends Recognizer { 238 | constructor() { 239 | super('IdBarcodeRecognizer'); 240 | 241 | this.createResultFromNative = function (nativeResult) { return new IdBarcodeRecognizerResult(nativeResult); } 242 | } 243 | } -------------------------------------------------------------------------------- /BlinkID/recognizers/mrtdCombinedRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | Date, 4 | Point, 5 | Quadrilateral, 6 | MrtdDocumentType, 7 | MrzResult, 8 | DocumentFaceDetectorType, 9 | Country, 10 | Region, 11 | Type, 12 | DocumentImageColorStatus, 13 | DocumentImageMoireStatus, 14 | AnonymizationMode, 15 | RecognitionModeFilter, 16 | StrictnessLevel, 17 | ClassFilter, 18 | 19 | 20 | ImageExtensionFactors, 21 | DataMatchResult, 22 | } from '../types' 23 | 24 | /** 25 | * Result object for MrtdCombinedRecognizer. 26 | */ 27 | export class MrtdCombinedRecognizerResult extends RecognizerResult { 28 | constructor(nativeResult) { 29 | super(nativeResult.resultState); 30 | 31 | /** 32 | * Returns DataMatchStateSuccess if data from scanned parts/sides of the document match, 33 | * DataMatchStateFailed otherwise. For example if date of expiry is scanned from the front and back side 34 | * of the document and values do not match, this method will return DataMatchStateFailed. Result will 35 | * be DataMatchStateSuccess only if scanned values for all fields that are compared are the same. 36 | */ 37 | this.documentDataMatch = nativeResult.documentDataMatch; 38 | 39 | /** 40 | * face image from the document if enabled with returnFaceImage property. 41 | */ 42 | this.faceImage = nativeResult.faceImage; 43 | 44 | /** 45 | * back side image of the document if enabled with returnFullDocumentImage property. 46 | */ 47 | this.fullDocumentBackImage = nativeResult.fullDocumentBackImage; 48 | 49 | /** 50 | * front side image of the document if enabled with returnFullDocumentImage property. 51 | */ 52 | this.fullDocumentFrontImage = nativeResult.fullDocumentFrontImage; 53 | 54 | /** 55 | * Returns the Data extracted from the machine readable zone. 56 | */ 57 | this.mrzResult = nativeResult.mrzResult != null ? new MrzResult(nativeResult.mrzResult) : null; 58 | 59 | /** 60 | * Returns true if recognizer has finished scanning first side and is now scanning back side, 61 | * false if it's still scanning first side. 62 | */ 63 | this.scanningFirstSideDone = nativeResult.scanningFirstSideDone; 64 | 65 | } 66 | } 67 | 68 | /** 69 | * MRTD Combined recognizer 70 | * 71 | * MRTD Combined recognizer is used for scanning both front and back side of generic IDs. 72 | */ 73 | export class MrtdCombinedRecognizer extends Recognizer { 74 | constructor() { 75 | super('MrtdCombinedRecognizer'); 76 | 77 | /** 78 | * Whether special characters are allowed 79 | * 80 | * 81 | */ 82 | this.allowSpecialCharacters = false; 83 | 84 | /** 85 | * Whether returning of unparsed results is allowed 86 | * 87 | * 88 | */ 89 | this.allowUnparsedResults = false; 90 | 91 | /** 92 | * Whether returning of unverified results is allowed 93 | * Unverified result is result that is parsed, but check digits are incorrect. 94 | * 95 | * 96 | */ 97 | this.allowUnverifiedResults = false; 98 | 99 | /** 100 | * Type of document this recognizer will scan. 101 | * 102 | * 103 | */ 104 | this.detectorType = DocumentFaceDetectorType.TD1; 105 | 106 | /** 107 | * Property for setting DPI for face images 108 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 109 | * 110 | * 111 | */ 112 | this.faceImageDpi = 250; 113 | 114 | /** 115 | * Property for setting DPI for full document images 116 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 117 | * 118 | * 119 | */ 120 | this.fullDocumentImageDpi = 250; 121 | 122 | /** 123 | * Image extension factors for full document image. 124 | * 125 | * @see ImageExtensionFactors 126 | * 127 | */ 128 | this.fullDocumentImageExtensionFactors = new ImageExtensionFactors(); 129 | 130 | /** 131 | * Defines how many times the same document should be detected before the detector 132 | * returns this document as a result of the deteciton 133 | * 134 | * Higher number means more reliable detection, but slower processing 135 | * 136 | * 137 | */ 138 | this.numStableDetectionsThreshold = 6; 139 | 140 | /** 141 | * Sets whether face image from ID card should be extracted 142 | * 143 | * 144 | */ 145 | this.returnFaceImage = false; 146 | 147 | /** 148 | * Sets whether full document image of ID card should be extracted. 149 | * 150 | * 151 | */ 152 | this.returnFullDocumentImage = false; 153 | 154 | this.createResultFromNative = function (nativeResult) { return new MrtdCombinedRecognizerResult(nativeResult); } 155 | } 156 | } -------------------------------------------------------------------------------- /BlinkID/recognizers/mrtdRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | Date, 4 | Point, 5 | Quadrilateral, 6 | MrtdDocumentType, 7 | MrzResult, 8 | DocumentFaceDetectorType, 9 | Country, 10 | Region, 11 | Type, 12 | DocumentImageColorStatus, 13 | DocumentImageMoireStatus, 14 | AnonymizationMode, 15 | RecognitionModeFilter, 16 | StrictnessLevel, 17 | ClassFilter, 18 | 19 | 20 | ImageExtensionFactors, 21 | DataMatchResult, 22 | } from '../types' 23 | 24 | /** 25 | * Result object for MrtdRecognizer. 26 | */ 27 | export class MrtdRecognizerResult extends RecognizerResult { 28 | constructor(nativeResult) { 29 | super(nativeResult.resultState); 30 | 31 | /** 32 | * full document image if enabled with returnFullDocumentImage property. 33 | */ 34 | this.fullDocumentImage = nativeResult.fullDocumentImage; 35 | 36 | /** 37 | * Returns the Data extracted from the machine readable zone. 38 | */ 39 | this.mrzResult = nativeResult.mrzResult != null ? new MrzResult(nativeResult.mrzResult) : null; 40 | 41 | } 42 | } 43 | 44 | /** 45 | * Recognizer that can recognizer Machine Readable Zone (MRZ) of the Machine Readable Travel Document (MRTD) 46 | */ 47 | export class MrtdRecognizer extends Recognizer { 48 | constructor() { 49 | super('MrtdRecognizer'); 50 | 51 | /** 52 | * Whether special characters are allowed 53 | * 54 | * 55 | */ 56 | this.allowSpecialCharacters = false; 57 | 58 | /** 59 | * Whether returning of unparsed results is allowed 60 | * 61 | * 62 | */ 63 | this.allowUnparsedResults = false; 64 | 65 | /** 66 | * Whether returning of unverified results is allowed 67 | * Unverified result is result that is parsed, but check digits are incorrect. 68 | * 69 | * 70 | */ 71 | this.allowUnverifiedResults = false; 72 | 73 | /** 74 | * Defines if glare detection should be turned on/off. 75 | * 76 | * 77 | */ 78 | this.detectGlare = true; 79 | 80 | /** 81 | * Property for setting DPI for full document images 82 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 83 | * 84 | * 85 | */ 86 | this.fullDocumentImageDpi = 250; 87 | 88 | /** 89 | * Image extension factors for full document image. 90 | * 91 | * @see ImageExtensionFactors 92 | * 93 | */ 94 | this.fullDocumentImageExtensionFactors = new ImageExtensionFactors(); 95 | 96 | /** 97 | * Sets whether full document image of ID card should be extracted. 98 | * 99 | * 100 | */ 101 | this.returnFullDocumentImage = false; 102 | 103 | this.createResultFromNative = function (nativeResult) { return new MrtdRecognizerResult(nativeResult); } 104 | } 105 | } -------------------------------------------------------------------------------- /BlinkID/recognizers/passportRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | Date, 4 | Point, 5 | Quadrilateral, 6 | MrtdDocumentType, 7 | MrzResult, 8 | DocumentFaceDetectorType, 9 | Country, 10 | Region, 11 | Type, 12 | DocumentImageColorStatus, 13 | DocumentImageMoireStatus, 14 | AnonymizationMode, 15 | RecognitionModeFilter, 16 | StrictnessLevel, 17 | ClassFilter, 18 | 19 | 20 | ImageExtensionFactors, 21 | DataMatchResult, 22 | } from '../types' 23 | 24 | /** 25 | * Result object for PassportRecognizer. 26 | */ 27 | export class PassportRecognizerResult extends RecognizerResult { 28 | constructor(nativeResult) { 29 | super(nativeResult.resultState); 30 | 31 | /** 32 | * face image from the document if enabled with returnFaceImage property. 33 | */ 34 | this.faceImage = nativeResult.faceImage; 35 | 36 | /** 37 | * full document image if enabled with returnFullDocumentImage property. 38 | */ 39 | this.fullDocumentImage = nativeResult.fullDocumentImage; 40 | 41 | /** 42 | * The data extracted from the machine readable zone. 43 | */ 44 | this.mrzResult = nativeResult.mrzResult != null ? new MrzResult(nativeResult.mrzResult) : null; 45 | 46 | } 47 | } 48 | 49 | /** 50 | * Recognizer which can scan all passports with MRZ. 51 | */ 52 | export class PassportRecognizer extends Recognizer { 53 | constructor() { 54 | super('PassportRecognizer'); 55 | 56 | /** 57 | * Defines whether to anonymize Netherlands MRZ 58 | * 59 | * 60 | */ 61 | this.anonymizeNetherlandsMrz = true; 62 | 63 | /** 64 | * Defines if glare detection should be turned on/off. 65 | * 66 | * 67 | */ 68 | this.detectGlare = true; 69 | 70 | /** 71 | * Property for setting DPI for face images 72 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 73 | * 74 | * 75 | */ 76 | this.faceImageDpi = 250; 77 | 78 | /** 79 | * Property for setting DPI for full document images 80 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 81 | * 82 | * 83 | */ 84 | this.fullDocumentImageDpi = 250; 85 | 86 | /** 87 | * Image extension factors for full document image. 88 | * 89 | * @see ImageExtensionFactors 90 | * 91 | */ 92 | this.fullDocumentImageExtensionFactors = new ImageExtensionFactors(); 93 | 94 | /** 95 | * Sets whether face image from ID card should be extracted 96 | * 97 | * 98 | */ 99 | this.returnFaceImage = false; 100 | 101 | /** 102 | * Sets whether full document image of ID card should be extracted. 103 | * 104 | * 105 | */ 106 | this.returnFullDocumentImage = false; 107 | 108 | this.createResultFromNative = function (nativeResult) { return new PassportRecognizerResult(nativeResult); } 109 | } 110 | } -------------------------------------------------------------------------------- /BlinkID/recognizers/successFrameGrabberRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | 3 | /** 4 | * Result object for SuccessFrameGrabberRecognizer. 5 | */ 6 | export class SuccessFrameGrabberRecognizerResult extends RecognizerResult { 7 | constructor(nativeResult, slaveRecognizerResult) { 8 | super(nativeResult.resultState); 9 | 10 | /** Camera frame at the time slave recognizer finished recognition */ 11 | this.successFrame = nativeResult.successFrame; 12 | 13 | /** RecognizerResult of the slave recognizer */ 14 | this.slaveRecognizerResult = slaveRecognizerResult; 15 | } 16 | } 17 | 18 | /** 19 | * SuccessFrameGrabberRecognizer can wrap any other recognizer and obtain camera 20 | * frame on which the other recognizer finished recognition. 21 | */ 22 | export class SuccessFrameGrabberRecognizer extends Recognizer { 23 | constructor(slaveRecognizer) { 24 | super('SuccessFrameGrabberRecognizer'); 25 | /** Slave recognizer that SuccessFrameGrabberRecognizer will watch */ 26 | this.slaveRecognizer = slaveRecognizer; 27 | 28 | if (!this.slaveRecognizer instanceof Recognizer) { 29 | throw new Error("Slave recognizer must be Recognizer!"); 30 | } 31 | 32 | this.createResultFromNative = (function (nativeResult) { return new SuccessFrameGrabberRecognizerResult(nativeResult, this.slaveRecognizer.createResultFromNative(nativeResult.slaveRecognizerResult)); }).bind(this); 33 | } 34 | } -------------------------------------------------------------------------------- /BlinkID/recognizers/usdlCombinedRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | ImageExtensionFactors, 4 | Date 5 | } from '../types' 6 | 7 | /** 8 | * Result object for UsdlCombinedRecognizer. 9 | */ 10 | export class UsdlCombinedRecognizerResult extends RecognizerResult { 11 | constructor(nativeResult) { 12 | super(nativeResult.resultState); 13 | 14 | /** 15 | * Returns true if data from scanned parts/sides of the document match, 16 | * false otherwise. For example if date of expiry is scanned from the front and back side 17 | * of the document and values do not match, this method will return false. Result will 18 | * be true only if scanned values for all fields that are compared are the same. 19 | */ 20 | this.documentDataMatch = nativeResult.documentDataMatch; 21 | 22 | /** 23 | * face image from the document if enabled with returnFaceImage property. 24 | */ 25 | this.faceImage = nativeResult.faceImage; 26 | 27 | /** 28 | * full document image if enabled with returnFullDocumentImage property. 29 | */ 30 | this.fullDocumentImage = nativeResult.fullDocumentImage; 31 | 32 | /** 33 | * Returns true if recognizer has finished scanning first side and is now scanning back side, 34 | * false if it's still scanning first side. 35 | */ 36 | this.scanningFirstSideDone = nativeResult.scanningFirstSideDone; 37 | 38 | /** Array of elements that are not part of AAMVA standard and are specific to each US state. */ 39 | this.optionalElements = nativeResult.optionalElements; 40 | 41 | /** The raw bytes contained inside 2D barcode. */ 42 | this.rawData = nativeResult.rawData; 43 | 44 | /** Raw string inside 2D barcode. */ 45 | this.rawStringData = nativeResult.rawStringData; 46 | 47 | /** True if returned result is uncertain, i.e. if scanned barcode was incomplete (i.e. */ 48 | this.uncertain = nativeResult.uncertain; 49 | 50 | /** Fields inside US Driver's licence. Available Keys are listed in UsdlKeys enum. */ 51 | this.fields = nativeResult.fields; 52 | 53 | /** The first name of the United States driver license owner. */ 54 | this.firstName = nativeResult.firstName; 55 | 56 | /** The middle name of the United States driver license owner. */ 57 | this.middleName = nativeResult.middleName; 58 | 59 | /** The last name of the United States driver license owner. */ 60 | this.lastName = nativeResult.lastName; 61 | 62 | /** The full name of the United States driver license owner. */ 63 | this.fullName = nativeResult.fullName; 64 | 65 | /** The name suffix of the United States driver license owner. */ 66 | this.nameSuffix = nativeResult.nameSuffix; 67 | 68 | /** The full address of the United States driver license owner. */ 69 | this.address = nativeResult.address; 70 | 71 | /** The document number of the United States driver license. */ 72 | this.documentNumber = nativeResult.documentNumber; 73 | 74 | /** The sex of the United States driver license owner. */ 75 | this.sex = nativeResult.sex; 76 | 77 | /** The restrictions to driving privileges for the United States driver license owner. */ 78 | this.restrictions = nativeResult.restrictions; 79 | 80 | /** The additional privileges granted to the United States driver license owner. */ 81 | this.endorsements = nativeResult.endorsements; 82 | 83 | /** The type of vehicle the driver license owner has privilege to drive. */ 84 | this.vehicleClass = nativeResult.vehicleClass; 85 | 86 | /** The date of birth of the United States driver license owner. */ 87 | this.dateOfBirth = nativeResult.dateOfBirth != null ? new Date(nativeResult.dateOfBirth) : null; 88 | 89 | /** The date of issue of the United States driver license. */ 90 | this.dateOfIssue = nativeResult.dateOfIssue != null ? new Date(nativeResult.dateOfIssue) : null; 91 | 92 | /** The date of expiry of the United States driver license. */ 93 | this.dateOfExpiry = nativeResult.dateOfExpiry != null ? new Date(nativeResult.dateOfExpiry) : null; 94 | 95 | /** 96 | * The current age of the document owner in years. It is calculated difference 97 | * between now and date of birth. Now is current time on the device. 98 | * @return current age of the document owner in years or -1 if date of birth is unknown. 99 | */ 100 | this.age = nativeResult.age; 101 | } 102 | } 103 | 104 | /** 105 | * USDL Combined Recognizer. 106 | * 107 | * USDL Combined recognizer is used for scanning both front and back side of US Driver's License. 108 | */ 109 | export class UsdlCombinedRecognizer extends Recognizer { 110 | constructor() { 111 | super('UsdlCombinedRecognizer'); 112 | 113 | /** 114 | * Property for setting DPI for face images 115 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 116 | * 117 | * 118 | */ 119 | this.faceImageDpi = 250; 120 | 121 | /** 122 | * Property for setting DPI for full document images 123 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 124 | * 125 | * 126 | */ 127 | this.fullDocumentImageDpi = 250; 128 | 129 | /** 130 | * Sets whether face image from ID card should be extracted 131 | * 132 | * 133 | */ 134 | this.returnFaceImage = false; 135 | 136 | /** 137 | * Sets whether full document image of ID card should be extracted. 138 | * 139 | * 140 | */ 141 | this.returnFullDocumentImage = false; 142 | 143 | /** 144 | * The extension factors for full document image. 145 | */ 146 | this.fullDocumentImageExtensionFactors = new ImageExtensionFactors(); 147 | 148 | /** 149 | * Minimum number of stable detections required for detection to be successful. 150 | */ 151 | this.numStableDetectionsThreshold = 6; 152 | 153 | this.createResultFromNative = function (nativeResult) { return new UsdlCombinedRecognizerResult(nativeResult); } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /BlinkID/recognizers/visaRecognizer.js: -------------------------------------------------------------------------------- 1 | import { Recognizer, RecognizerResult } from '../recognizer' 2 | import { 3 | Date, 4 | Point, 5 | Quadrilateral, 6 | MrtdDocumentType, 7 | MrzResult, 8 | DocumentFaceDetectorType, 9 | Country, 10 | Region, 11 | Type, 12 | DocumentImageColorStatus, 13 | DocumentImageMoireStatus, 14 | AnonymizationMode, 15 | RecognitionModeFilter, 16 | StrictnessLevel, 17 | ClassFilter, 18 | 19 | 20 | ImageExtensionFactors, 21 | DataMatchResult, 22 | } from '../types' 23 | 24 | /** 25 | * Result object for VisaRecognizer. 26 | */ 27 | export class VisaRecognizerResult extends RecognizerResult { 28 | constructor(nativeResult) { 29 | super(nativeResult.resultState); 30 | 31 | /** 32 | * face image from the document if enabled with returnFaceImage property. 33 | */ 34 | this.faceImage = nativeResult.faceImage; 35 | 36 | /** 37 | * full document image if enabled with returnFullDocumentImage property. 38 | */ 39 | this.fullDocumentImage = nativeResult.fullDocumentImage; 40 | 41 | /** 42 | * The data extracted from the machine readable zone. 43 | */ 44 | this.mrzResult = nativeResult.mrzResult != null ? new MrzResult(nativeResult.mrzResult) : null; 45 | 46 | } 47 | } 48 | 49 | /** 50 | * Recognizer which can scan all visas with MRZ. 51 | */ 52 | export class VisaRecognizer extends Recognizer { 53 | constructor() { 54 | super('VisaRecognizer'); 55 | 56 | /** 57 | * Defines if glare detection should be turned on/off. 58 | * 59 | * 60 | */ 61 | this.detectGlare = true; 62 | 63 | /** 64 | * Property for setting DPI for face images 65 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 66 | * 67 | * 68 | */ 69 | this.faceImageDpi = 250; 70 | 71 | /** 72 | * Property for setting DPI for full document images 73 | * Valid ranges are [100,400]. Setting DPI out of valid ranges throws an exception 74 | * 75 | * 76 | */ 77 | this.fullDocumentImageDpi = 250; 78 | 79 | /** 80 | * Image extension factors for full document image. 81 | * 82 | * @see ImageExtensionFactors 83 | * 84 | */ 85 | this.fullDocumentImageExtensionFactors = new ImageExtensionFactors(); 86 | 87 | /** 88 | * Sets whether face image from ID card should be extracted 89 | * 90 | * 91 | */ 92 | this.returnFaceImage = false; 93 | 94 | /** 95 | * Sets whether full document image of ID card should be extracted. 96 | * 97 | * 98 | */ 99 | this.returnFullDocumentImage = false; 100 | 101 | this.createResultFromNative = function (nativeResult) { return new VisaRecognizerResult(nativeResult); } 102 | } 103 | } -------------------------------------------------------------------------------- /BlinkID/src/android/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .gradle 3 | *.iml 4 | .idea -------------------------------------------------------------------------------- /BlinkID/src/android/build.gradle: -------------------------------------------------------------------------------- 1 | rootProject.allprojects { 2 | repositories { 3 | google() 4 | jcenter() 5 | maven { url 'https://maven.microblink.com' } 6 | } 7 | } 8 | 9 | apply plugin: 'com.android.library' 10 | 11 | android { 12 | compileSdkVersion 34 13 | 14 | defaultConfig { 15 | minSdkVersion 23 16 | targetSdkVersion 34 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation 'com.facebook.react:react-native:+' 28 | implementation('com.microblink:blinkid:6.13.0@aar') { 29 | transitive = true 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/BlinkIDReactPackage.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | public class BlinkIDReactPackage implements ReactPackage { 14 | 15 | @Override 16 | public List createNativeModules(ReactApplicationContext reactContext) { 17 | List nativeModules = new ArrayList<>(); 18 | nativeModules.add(new MicroblinkModule(reactContext)); 19 | return nativeModules; 20 | } 21 | 22 | public List> createJSModules() { 23 | return Collections.emptyList(); 24 | } 25 | 26 | @Override 27 | public List createViewManagers(ReactApplicationContext reactContext) { 28 | return Collections.emptyList(); 29 | } 30 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/SerializationUtils.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative; 2 | 3 | import android.graphics.Bitmap; 4 | import android.util.Base64; 5 | 6 | import com.facebook.react.bridge.ReadableMap; 7 | import com.facebook.react.bridge.WritableArray; 8 | import com.facebook.react.bridge.WritableMap; 9 | import com.facebook.react.bridge.WritableNativeArray; 10 | import com.facebook.react.bridge.WritableNativeMap; 11 | import com.microblink.blinkid.entities.recognizers.Recognizer; 12 | import com.microblink.blinkid.geometry.Point; 13 | import com.microblink.blinkid.geometry.Quadrilateral; 14 | import com.microblink.blinkid.geometry.Rectangle; 15 | import com.microblink.blinkid.image.Image; 16 | import com.microblink.blinkid.results.date.SimpleDate; 17 | import com.microblink.blinkid.results.date.Date; 18 | import com.microblink.blinkid.entities.recognizers.blinkid.imageoptions.extension.ImageExtensionFactors; 19 | 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.IOException; 22 | 23 | public abstract class SerializationUtils { 24 | private static final int COMPRESSED_IMAGE_QUALITY = 90; 25 | 26 | public static void addCommonRecognizerResultData(WritableMap jsonObject, T result) { 27 | jsonObject.putInt("resultState", serializeEnum(result.getResultState())); 28 | } 29 | 30 | public static WritableMap serializeSimpleDate(SimpleDate date) { 31 | if (date != null ) { 32 | WritableMap jsonDate = new WritableNativeMap(); 33 | jsonDate.putInt("day", date.getDay()); 34 | jsonDate.putInt("month", date.getMonth()); 35 | jsonDate.putInt("year", date.getYear()); 36 | return jsonDate; 37 | } else { 38 | return null; 39 | } 40 | } 41 | 42 | public static WritableMap serializeDate(Date dateResult) { 43 | if (dateResult == null) { 44 | return null; 45 | } else { 46 | return serializeSimpleDate(dateResult.getDate()); 47 | } 48 | } 49 | 50 | public static int serializeEnum(Enum e) { 51 | return e.ordinal(); 52 | } 53 | 54 | public static WritableArray serializeStringArray(String[] strings) { 55 | WritableArray jsonStrings = new WritableNativeArray(); 56 | for (String str : strings) { 57 | jsonStrings.pushString(str); 58 | } 59 | return jsonStrings; 60 | } 61 | 62 | public static String encodeImageBase64(Image image) { 63 | if (image == null) { 64 | return null; 65 | } 66 | Bitmap resultImgBmp = image.convertToBitmap(); 67 | if (resultImgBmp == null) { 68 | return null; 69 | } 70 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 71 | boolean success = resultImgBmp.compress(Bitmap.CompressFormat.JPEG, COMPRESSED_IMAGE_QUALITY, byteArrayOutputStream); 72 | String resultImgBase64 = null; 73 | if (success) { 74 | resultImgBase64 = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.NO_WRAP); 75 | } 76 | try { 77 | byteArrayOutputStream.close(); 78 | } catch (IOException ignorable) {} 79 | return resultImgBase64; 80 | } 81 | 82 | public static String encodeByteArrayToBase64(byte[] arr) { 83 | if (arr == null) { 84 | return null; 85 | } 86 | return Base64.encodeToString(arr, Base64.NO_WRAP); 87 | } 88 | 89 | public static WritableMap serializePoint(Point point) { 90 | WritableMap jsonPoint = new WritableNativeMap(); 91 | jsonPoint.putDouble("x", point.getX()); 92 | jsonPoint.putDouble("y", point.getY()); 93 | return jsonPoint; 94 | } 95 | 96 | public static WritableMap serializeQuad(Quadrilateral quad) { 97 | WritableMap jsonQuad = new WritableNativeMap(); 98 | jsonQuad.putMap("upperLeft", serializePoint(quad.getUpperLeft())); 99 | jsonQuad.putMap("upperRight", serializePoint(quad.getUpperRight())); 100 | jsonQuad.putMap("lowerLeft", serializePoint(quad.getLowerLeft())); 101 | jsonQuad.putMap("lowerRight", serializePoint(quad.getLowerRight())); 102 | return jsonQuad; 103 | } 104 | 105 | public static WritableMap serializeRectangle(Rectangle rectangle) { 106 | WritableMap jsonRectangle = new WritableNativeMap(); 107 | 108 | if (rectangle != null) { 109 | jsonRectangle.putDouble("x", rectangle.getX()); 110 | jsonRectangle.putDouble("y", rectangle.getY()); 111 | jsonRectangle.putDouble("height", rectangle.getHeight()); 112 | jsonRectangle.putDouble("width", rectangle.getWidth()); 113 | } 114 | return jsonRectangle; 115 | } 116 | 117 | public static ImageExtensionFactors deserializeExtensionFactors(ReadableMap jsonExtensionFactors) { 118 | if (jsonExtensionFactors == null) { 119 | return new ImageExtensionFactors(0.f, 0.f, 0.f, 0.f); 120 | } else { 121 | float up = (float)jsonExtensionFactors.getDouble("upFactor"); 122 | float right = (float)jsonExtensionFactors.getDouble("rightFactor"); 123 | float down = (float)jsonExtensionFactors.getDouble("downFactor"); 124 | float left = (float)jsonExtensionFactors.getDouble("leftFactor"); 125 | return new ImageExtensionFactors(up, down, left, right); 126 | } 127 | } 128 | 129 | public static String getStringFromMap(ReadableMap map, String key) { 130 | if (map.hasKey(key)) { 131 | return map.getString(key); 132 | } 133 | return null; 134 | } 135 | 136 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/OverlaySettingsSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays; 2 | 3 | import android.content.Context; 4 | 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.microblink.blinkid.entities.recognizers.RecognizerBundle; 7 | import com.microblink.blinkid.uisettings.UISettings; 8 | 9 | public interface OverlaySettingsSerialization { 10 | UISettings createUISettings(Context context, ReadableMap jsonUISettings, RecognizerBundle recognizerBundle); 11 | 12 | String getJsonName(); 13 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/OverlaySettingsSerializers.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays; 2 | 3 | import android.content.Context; 4 | 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.microblink.blinkid.entities.recognizers.RecognizerBundle; 7 | import com.microblink.blinkid.reactnative.overlays.serialization.*; 8 | import com.microblink.blinkid.uisettings.UISettings; 9 | 10 | import java.util.HashMap; 11 | 12 | public enum OverlaySettingsSerializers { 13 | INSTANCE; 14 | 15 | private HashMap mByJSONName = new HashMap<>(); 16 | 17 | private void registerMapping(OverlaySettingsSerialization overlaySettingsSerialization) { 18 | mByJSONName.put(overlaySettingsSerialization.getJsonName(), overlaySettingsSerialization); 19 | } 20 | 21 | OverlaySettingsSerializers() { 22 | registerMapping(new DocumentOverlaySettingsSerialization()); 23 | registerMapping(new DocumentVerificationOverlaySettingsSerialization()); 24 | registerMapping(new BlinkIdOverlaySettingsSerialization()); 25 | } 26 | 27 | public UISettings getOverlaySettings(Context context, ReadableMap jsonOverlaySettings, RecognizerBundle recognizerBundle) { 28 | return mByJSONName.get(jsonOverlaySettings.getString("overlaySettingsType")).createUISettings(context, jsonOverlaySettings, recognizerBundle); 29 | } 30 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/serialization/BlinkIDOverlaySerializationUtils.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.microblink.blinkid.uisettings.UISettings; 5 | 6 | public abstract class BlinkIDOverlaySerializationUtils { 7 | public static void extractCommonBlinkIdUiSettings(ReadableMap jsonOverlaySettings, UISettings uiSettings) { 8 | } 9 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/serialization/BlinkIdOverlaySettingsSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays.serialization; 2 | 3 | import android.content.Context; 4 | 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.microblink.blinkid.entities.recognizers.RecognizerBundle; 7 | import com.microblink.blinkid.fragment.overlay.blinkid.reticleui.ReticleOverlayStrings; 8 | import com.microblink.blinkid.reactnative.overlays.OverlaySettingsSerialization; 9 | import com.microblink.blinkid.uisettings.BlinkIdUISettings; 10 | import com.microblink.blinkid.uisettings.UISettings; 11 | import com.microblink.blinkid.locale.LanguageUtils; 12 | import com.microblink.blinkid.hardware.camera.VideoResolutionPreset; 13 | import com.microblink.blinkid.uisettings.CameraSettings; 14 | 15 | 16 | import static com.microblink.blinkid.reactnative.SerializationUtils.getStringFromMap; 17 | 18 | public final class BlinkIdOverlaySettingsSerialization implements OverlaySettingsSerialization { 19 | @Override 20 | public UISettings createUISettings(Context context, ReadableMap jsonUISettings, RecognizerBundle recognizerBundle) { 21 | BlinkIdUISettings settings = new BlinkIdUISettings(recognizerBundle); 22 | OverlaySerializationUtils.extractCommonUISettings(jsonUISettings, settings); 23 | 24 | BlinkIDOverlaySerializationUtils.extractCommonBlinkIdUiSettings(jsonUISettings, settings); 25 | 26 | Boolean requireDocumentSidesDataMatch = getBooleanFromMap(jsonUISettings, "requireDocumentSidesDataMatch"); 27 | if (requireDocumentSidesDataMatch != null) { 28 | settings.setDocumentDataMatchRequired(requireDocumentSidesDataMatch); 29 | } 30 | 31 | String language = getStringFromMap(jsonUISettings, "language"); 32 | if (language != null) { 33 | String country = jsonUISettings.hasKey("country") ? jsonUISettings.getString("country") : null; 34 | LanguageUtils.setLanguageAndCountry(language, country, context); 35 | } 36 | 37 | Boolean showNotSupportedDialog = getBooleanFromMap(jsonUISettings, "showNotSupportedDialog"); 38 | if (showNotSupportedDialog != null) { 39 | settings.setShowNotSupportedDialog(showNotSupportedDialog); 40 | } 41 | 42 | Boolean showFlashlightWarning = getBooleanFromMap(jsonUISettings, "showFlashlightWarning"); 43 | if (showFlashlightWarning != null) { 44 | settings.setShowFlashlightWarning(showFlashlightWarning); 45 | } 46 | 47 | Boolean showMandatoryFieldsMissing = getBooleanFromMap(jsonUISettings, "showMandatoryFieldsMissing"); 48 | if (showMandatoryFieldsMissing != null) { 49 | settings.setShowMandatoryFieldsMissing(showMandatoryFieldsMissing); 50 | } 51 | 52 | Boolean showOnboardingInfo = getBooleanFromMap(jsonUISettings, "showOnboardingInfo"); 53 | if (showOnboardingInfo != null) { 54 | settings.setShowOnboardingInfo(showOnboardingInfo); 55 | } 56 | 57 | Boolean showIntroductionDialog = getBooleanFromMap(jsonUISettings, "showIntroductionDialog"); 58 | if (showIntroductionDialog != null) { 59 | settings.setShowIntroductionDialog(showIntroductionDialog); 60 | } 61 | 62 | Boolean showTorchButton = getBooleanFromMap(jsonUISettings, "showTorchButton"); 63 | if (showTorchButton != null) { 64 | settings.setShowTorchButton(showTorchButton); 65 | } 66 | 67 | Boolean showCancelButton = getBooleanFromMap(jsonUISettings, "showCancelButton"); 68 | if (showCancelButton != null) { 69 | settings.setShowCancelButton(showCancelButton); 70 | } 71 | 72 | if (jsonUISettings.hasKey("onboardingButtonTooltipDelay")) { 73 | settings.setShowTooltipTimeIntervalMs(jsonUISettings.getInt("onboardingButtonTooltipDelay")); 74 | } 75 | 76 | if (jsonUISettings.hasKey("backSideScanningTimeoutMilliseconds")) { 77 | settings.setBackSideScanningTimeoutMs(jsonUISettings.getInt("backSideScanningTimeoutMilliseconds")); 78 | } 79 | 80 | VideoResolutionPreset videoResolutionPreset = VideoResolutionPreset.values()[0]; 81 | if (jsonUISettings.hasKey("androidCameraResolutionPreset")) { 82 | videoResolutionPreset = VideoResolutionPreset.values()[jsonUISettings.getInt("androidCameraResolutionPreset")]; 83 | } 84 | 85 | Boolean androidLegacyCameraApi = false; 86 | if (jsonUISettings.hasKey("enableAndroidLegacyCameraApi")) { 87 | androidLegacyCameraApi = jsonUISettings.getBoolean("enableAndroidLegacyCameraApi"); 88 | } 89 | 90 | settings.setCameraSettings(new CameraSettings.Builder() 91 | .setVideoResolutionPreset(videoResolutionPreset) 92 | .setForceLegacyApi(androidLegacyCameraApi) 93 | .build()); 94 | 95 | ReticleOverlayStrings.Builder overlasStringsBuilder = new ReticleOverlayStrings.Builder(context); 96 | 97 | String firstSideInstructionsText = getStringFromMap(jsonUISettings, "firstSideInstructionsText"); 98 | if (firstSideInstructionsText != null) { 99 | overlasStringsBuilder.setFirstSideInstructionsText(firstSideInstructionsText); 100 | } 101 | String flipInstructions = getStringFromMap(jsonUISettings, "flipInstructions"); 102 | if (flipInstructions != null) { 103 | overlasStringsBuilder.setFlipInstructions(flipInstructions); 104 | } 105 | String errorMoveCloser = getStringFromMap(jsonUISettings, "errorMoveCloser"); 106 | if (errorMoveCloser != null) { 107 | overlasStringsBuilder.setErrorMoveCloser(errorMoveCloser); 108 | } 109 | String errorMoveFarther = getStringFromMap(jsonUISettings, "errorMoveFarther"); 110 | if (errorMoveFarther != null) { 111 | overlasStringsBuilder.setErrorMoveFarther(errorMoveFarther); 112 | } 113 | String sidesNotMatchingTitle = getStringFromMap(jsonUISettings, "sidesNotMatchingTitle"); 114 | if (sidesNotMatchingTitle != null) { 115 | overlasStringsBuilder.setSidesNotMatchingTitle(sidesNotMatchingTitle); 116 | } 117 | String sidesNotMatchingMessage = getStringFromMap(jsonUISettings, "sidesNotMatchingMessage"); 118 | if (sidesNotMatchingMessage != null) { 119 | overlasStringsBuilder.setSidesNotMatchingMessage(sidesNotMatchingMessage); 120 | } 121 | String unsupportedDocumentTitle = getStringFromMap(jsonUISettings, "unsupportedDocumentTitle"); 122 | if (unsupportedDocumentTitle != null) { 123 | overlasStringsBuilder.setUnsupportedDocumentTitle(unsupportedDocumentTitle); 124 | } 125 | String unsupportedDocumentMessage = getStringFromMap(jsonUISettings, "unsupportedDocumentMessage"); 126 | if (unsupportedDocumentMessage != null) { 127 | overlasStringsBuilder.setUnsupportedDocumentMessage(unsupportedDocumentMessage); 128 | } 129 | String recognitionTimeoutTitle = getStringFromMap(jsonUISettings, "recognitionTimeoutTitle"); 130 | if (recognitionTimeoutTitle != null) { 131 | overlasStringsBuilder.setRecognitionTimeoutTitle(recognitionTimeoutTitle); 132 | } 133 | String recognitionTimeoutMessage = getStringFromMap(jsonUISettings, "recognitionTimeoutMessage"); 134 | if (recognitionTimeoutMessage != null) { 135 | overlasStringsBuilder.setRecognitionTimeoutMessage(recognitionTimeoutMessage); 136 | } 137 | String retryButtonText = getStringFromMap(jsonUISettings, "retryButtonText"); 138 | if (retryButtonText != null) { 139 | overlasStringsBuilder.setRetryButtonText(retryButtonText); 140 | } 141 | String scanBarcodeText = getStringFromMap(jsonUISettings, "scanBarcodeText"); 142 | if (scanBarcodeText != null) { 143 | overlasStringsBuilder.setBackSideBarcodeInstructions(scanBarcodeText); 144 | } 145 | String errorDocumentTooCloseToEdge = getStringFromMap(jsonUISettings, "errorDocumentTooCloseToEdge"); 146 | if (errorDocumentTooCloseToEdge != null) { 147 | overlasStringsBuilder.setErrorDocumentTooCloseToEdge(errorDocumentTooCloseToEdge); 148 | } 149 | String errorBlurDetected = getStringFromMap(jsonUISettings, "errorBlurDetected"); 150 | if (errorBlurDetected != null) { 151 | overlasStringsBuilder.setErrorBlurDetected(errorBlurDetected); 152 | } 153 | String errorGlareDetected = getStringFromMap(jsonUISettings, "errorGlareDetected"); 154 | if (errorGlareDetected != null) { 155 | overlasStringsBuilder.setErrorGlareDetected(errorGlareDetected); 156 | } 157 | String topPageInstructions = getStringFromMap(jsonUISettings, "topPageInstructions"); 158 | if (topPageInstructions != null) { 159 | overlasStringsBuilder.setTopPageInstructions(topPageInstructions); 160 | } 161 | String leftPageInstructions = getStringFromMap(jsonUISettings, "leftPageInstructions"); 162 | if (leftPageInstructions != null) { 163 | overlasStringsBuilder.setLeftPageInstructions(leftPageInstructions); 164 | } 165 | String rightPageInstructions = getStringFromMap(jsonUISettings, "rightPageInstructions"); 166 | if (rightPageInstructions != null) { 167 | overlasStringsBuilder.setRightPageInstructions(rightPageInstructions); 168 | } 169 | String turnTopPageInstructions = getStringFromMap(jsonUISettings, "turnTopPageInstructions"); 170 | if (turnTopPageInstructions != null) { 171 | overlasStringsBuilder.setTurnTopPageInstructions(turnTopPageInstructions); 172 | } 173 | String turnLeftPageInstructions = getStringFromMap(jsonUISettings, "turnLeftPageInstructions"); 174 | if (turnLeftPageInstructions != null) { 175 | overlasStringsBuilder.setTurnLeftPageInstructions(turnLeftPageInstructions); 176 | } 177 | String turnRightPageInstructions = getStringFromMap(jsonUISettings, "turnRightPageInstructions"); 178 | if (turnRightPageInstructions != null) { 179 | overlasStringsBuilder.setTurnRightPageInstructions(turnRightPageInstructions); 180 | } 181 | String errorScanningWrongPageTop = getStringFromMap(jsonUISettings, "errorScanningWrongPageTop"); 182 | if (errorScanningWrongPageTop != null) { 183 | overlasStringsBuilder.setErrorScanningWrongPageTop(errorScanningWrongPageTop); 184 | } 185 | String errorScanningWrongPageLeft = getStringFromMap(jsonUISettings, "errorScanningWrongPageLeft"); 186 | if (errorScanningWrongPageLeft != null) { 187 | overlasStringsBuilder.setErrorScanningWrongPageLeft(errorScanningWrongPageLeft); 188 | } 189 | String errorScanningWrongPageRight = getStringFromMap(jsonUISettings, "errorScanningWrongPageRight"); 190 | if (errorScanningWrongPageRight != null) { 191 | overlasStringsBuilder.setErrorScanningWrongPageRight(errorScanningWrongPageRight); 192 | } 193 | 194 | settings.setStrings(overlasStringsBuilder.build()); 195 | 196 | return settings; 197 | } 198 | 199 | public static Boolean getBooleanFromMap(ReadableMap map, String key) { 200 | if (map.hasKey(key)) { 201 | return map.getBoolean(key); 202 | } 203 | return null; 204 | } 205 | 206 | @Override 207 | public String getJsonName() { 208 | return "BlinkIdOverlaySettings"; 209 | } 210 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/serialization/DocumentOverlaySettingsSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays.serialization; 2 | 3 | import android.content.Context; 4 | 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.microblink.blinkid.entities.recognizers.RecognizerBundle; 7 | import com.microblink.blinkid.reactnative.overlays.OverlaySettingsSerialization; 8 | import com.microblink.blinkid.uisettings.DocumentUISettings; 9 | import com.microblink.blinkid.uisettings.UISettings; 10 | 11 | public final class DocumentOverlaySettingsSerialization implements OverlaySettingsSerialization { 12 | @Override 13 | public UISettings createUISettings(Context context, ReadableMap jsonUISettings, RecognizerBundle recognizerBundle) { 14 | DocumentUISettings settings = new DocumentUISettings(recognizerBundle); 15 | OverlaySerializationUtils.extractCommonUISettings(jsonUISettings, settings); 16 | BlinkIDOverlaySerializationUtils.extractCommonBlinkIdUiSettings(jsonUISettings, settings); 17 | return settings; 18 | } 19 | 20 | @Override 21 | public String getJsonName() { 22 | return "DocumentOverlaySettings"; 23 | } 24 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/serialization/DocumentVerificationOverlaySettingsSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays.serialization; 2 | 3 | import android.content.Context; 4 | 5 | import com.facebook.react.bridge.ReadableMap; 6 | import com.microblink.blinkid.entities.recognizers.RecognizerBundle; 7 | import com.microblink.blinkid.fragment.overlay.blinkid.legacy.documentverification.LegacyDocumentVerificationOverlayStrings; 8 | import com.microblink.blinkid.reactnative.overlays.OverlaySettingsSerialization; 9 | import com.microblink.blinkid.uisettings.LegacyDocumentVerificationUISettings; 10 | import com.microblink.blinkid.uisettings.UISettings; 11 | 12 | import static com.microblink.blinkid.reactnative.SerializationUtils.getStringFromMap; 13 | 14 | public final class DocumentVerificationOverlaySettingsSerialization implements OverlaySettingsSerialization { 15 | @Override 16 | public UISettings createUISettings(Context context, ReadableMap jsonUISettings, RecognizerBundle recognizerBundle) { 17 | LegacyDocumentVerificationUISettings settings = new LegacyDocumentVerificationUISettings(recognizerBundle); 18 | OverlaySerializationUtils.extractCommonUISettings(jsonUISettings, settings); 19 | BlinkIDOverlaySerializationUtils.extractCommonBlinkIdUiSettings(jsonUISettings, settings); 20 | 21 | LegacyDocumentVerificationOverlayStrings.Builder stringsBuilder = new LegacyDocumentVerificationOverlayStrings.Builder(context); 22 | 23 | String firstSideSplashMessage = getStringFromMap(jsonUISettings, "firstSideSplashMessage"); 24 | if (firstSideSplashMessage != null) { 25 | stringsBuilder.setFrontSideSplashText(firstSideSplashMessage); 26 | } 27 | String secondSideSplashMessage = getStringFromMap(jsonUISettings, "secondSideSplashMessage"); 28 | if (secondSideSplashMessage != null) { 29 | stringsBuilder.setBackSideSplashText(secondSideSplashMessage); 30 | } 31 | String firstSideInstructions = getStringFromMap(jsonUISettings, "firstSideInstructions"); 32 | if (firstSideInstructions != null) { 33 | stringsBuilder.setFrontSideInstructions(firstSideInstructions); 34 | } 35 | String secondSideInstructions = getStringFromMap(jsonUISettings, "secondSideInstructions"); 36 | if (secondSideInstructions != null) { 37 | stringsBuilder.setBackSideInstructions(secondSideInstructions); 38 | } 39 | String glareMessage = getStringFromMap(jsonUISettings, "glareMessage"); 40 | if (glareMessage != null) { 41 | stringsBuilder.setGlareMessage(glareMessage); 42 | } 43 | settings.setStrings(stringsBuilder.build()); 44 | return settings; 45 | } 46 | 47 | @Override 48 | public String getJsonName() { 49 | return "DocumentVerificationOverlaySettings"; 50 | } 51 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/overlays/serialization/OverlaySerializationUtils.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.overlays.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.microblink.blinkid.hardware.camera.CameraType; 5 | import com.microblink.blinkid.reactnative.R; 6 | import com.microblink.blinkid.uisettings.CameraSettings; 7 | import com.microblink.blinkid.uisettings.UISettings; 8 | import com.microblink.blinkid.uisettings.options.BeepSoundUIOptions; 9 | 10 | public abstract class OverlaySerializationUtils { 11 | public static void extractCommonUISettings(ReadableMap jsonOverlaySettings, UISettings uiSettings) { 12 | if (uiSettings instanceof BeepSoundUIOptions) { 13 | if (jsonOverlaySettings.hasKey("enableBeep")) { 14 | if (jsonOverlaySettings.getBoolean("enableBeep")) { 15 | ((BeepSoundUIOptions)uiSettings).setBeepSoundResourceID(R.raw.beep); 16 | } 17 | } 18 | } 19 | if (jsonOverlaySettings.hasKey("useFrontCamera") 20 | && jsonOverlaySettings.getBoolean("useFrontCamera")) { 21 | CameraSettings cameraSettings = new CameraSettings.Builder() 22 | .setType(CameraType.CAMERA_FRONTFACE) 23 | .build(); 24 | uiSettings.setCameraSettings(cameraSettings); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/RecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.microblink.blinkid.entities.recognizers.Recognizer; 6 | 7 | public interface RecognizerSerialization { 8 | Recognizer createRecognizer(ReadableMap jsonRecognizer); 9 | WritableMap serializeResult(Recognizer recognizer); 10 | 11 | String getJsonName(); 12 | Class getRecognizerClass(); 13 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/RecognizerSerializers.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers; 2 | 3 | import com.facebook.react.bridge.ReadableArray; 4 | import com.facebook.react.bridge.ReadableMap; 5 | import com.facebook.react.bridge.WritableArray; 6 | import com.facebook.react.bridge.WritableNativeArray; 7 | import com.microblink.blinkid.entities.recognizers.Recognizer; 8 | import com.microblink.blinkid.entities.recognizers.RecognizerBundle; 9 | import com.microblink.blinkid.reactnative.recognizers.serialization.*; 10 | 11 | import java.util.HashMap; 12 | 13 | public enum RecognizerSerializers { 14 | INSTANCE; 15 | 16 | private HashMap recognizersByJSONName = new HashMap<>(); 17 | private HashMap, RecognizerSerialization> recognizersByClass = new HashMap<>(); 18 | 19 | RecognizerSerializers() { 20 | registerMapping(new SuccessFrameGrabberRecognizerSerialization()); 21 | registerMapping(new BlinkIdMultiSideRecognizerSerialization()); 22 | registerMapping(new BlinkIdSingleSideRecognizerSerialization()); 23 | registerMapping(new DocumentFaceRecognizerSerialization()); 24 | registerMapping(new IdBarcodeRecognizerSerialization()); 25 | registerMapping(new MrtdCombinedRecognizerSerialization()); 26 | registerMapping(new MrtdRecognizerSerialization()); 27 | registerMapping(new PassportRecognizerSerialization()); 28 | registerMapping(new VisaRecognizerSerialization()); 29 | registerMapping(new UsdlRecognizerSerialization()); 30 | registerMapping(new UsdlCombinedRecognizerSerialization()); 31 | 32 | } 33 | 34 | private void registerMapping( RecognizerSerialization recognizerSerialization ) { 35 | recognizersByJSONName.put(recognizerSerialization.getJsonName(), recognizerSerialization); 36 | recognizersByClass.put(recognizerSerialization.getRecognizerClass(), recognizerSerialization); 37 | } 38 | 39 | 40 | public RecognizerSerialization getRecognizerSerialization(ReadableMap jsonRecognizer) { 41 | return recognizersByJSONName.get(jsonRecognizer.getString("recognizerType")); 42 | } 43 | 44 | public RecognizerSerialization getRecognizerSerialization(Recognizer recognizer) { 45 | return recognizersByClass.get(recognizer.getClass()); 46 | } 47 | 48 | public RecognizerBundle deserializeRecognizerCollection(ReadableMap jsonRecognizerCollection) { 49 | ReadableArray recognizerArray = jsonRecognizerCollection.getArray("recognizerArray"); 50 | int numRecognizers = recognizerArray.size(); 51 | Recognizer[] recognizers = new Recognizer[numRecognizers]; 52 | for (int i = 0; i < numRecognizers; ++i) { 53 | recognizers[ i ] = getRecognizerSerialization(recognizerArray.getMap(i)).createRecognizer(recognizerArray.getMap(i)); 54 | } 55 | RecognizerBundle recognizerBundle = new RecognizerBundle(recognizers); 56 | 57 | if (jsonRecognizerCollection.hasKey("allowMultipleResults")) { 58 | recognizerBundle.setAllowMultipleScanResultsOnSingleImage(jsonRecognizerCollection.getBoolean("allowMultipleResults")); 59 | } 60 | if (jsonRecognizerCollection.hasKey("milisecondsBeforeTimeout")) { 61 | recognizerBundle.setNumMsBeforeTimeout(jsonRecognizerCollection.getInt("milisecondsBeforeTimeout")); 62 | } 63 | return recognizerBundle; 64 | } 65 | 66 | public WritableArray serializeRecognizerResults(Recognizer[] recognizers) { 67 | WritableArray jsonArray = new WritableNativeArray(); 68 | 69 | for (Recognizer recognizer : recognizers) { 70 | jsonArray.pushMap(getRecognizerSerialization(recognizer).serializeResult(recognizer)); 71 | } 72 | 73 | return jsonArray; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/DocumentFaceRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 8 | import com.microblink.blinkid.reactnative.SerializationUtils; 9 | 10 | public final class DocumentFaceRecognizerSerialization implements RecognizerSerialization { 11 | @Override 12 | public Recognizer createRecognizer(ReadableMap jsonMap) { 13 | com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer(); 14 | if (jsonMap.hasKey("detectorType")) { 15 | recognizer.setDetectorType(com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceDetectorType.values()[jsonMap.getInt("detectorType")]); 16 | } 17 | if (jsonMap.hasKey("faceImageDpi")) { 18 | recognizer.setFaceImageDpi(jsonMap.getInt("faceImageDpi")); 19 | } 20 | if (jsonMap.hasKey("fullDocumentImageDpi")) { 21 | recognizer.setFullDocumentImageDpi(jsonMap.getInt("fullDocumentImageDpi")); 22 | } 23 | if (jsonMap.hasKey("fullDocumentImageExtensionFactors")) { 24 | recognizer.setFullDocumentImageExtensionFactors(SerializationUtils.deserializeExtensionFactors(jsonMap.getMap("fullDocumentImageExtensionFactors"))); 25 | } 26 | if (jsonMap.hasKey("numStableDetectionsThreshold")) { 27 | recognizer.setNumStableDetectionsThreshold(jsonMap.getInt("numStableDetectionsThreshold")); 28 | } 29 | if (jsonMap.hasKey("returnFaceImage")) { 30 | recognizer.setReturnFaceImage(jsonMap.getBoolean("returnFaceImage")); 31 | } 32 | if (jsonMap.hasKey("returnFullDocumentImage")) { 33 | recognizer.setReturnFullDocumentImage(jsonMap.getBoolean("returnFullDocumentImage")); 34 | } 35 | return recognizer; 36 | } 37 | 38 | @Override 39 | public WritableMap serializeResult(Recognizer recognizer) { 40 | com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer.Result result = ((com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer)recognizer).getResult(); 41 | WritableMap jsonResult = new WritableNativeMap(); 42 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 43 | jsonResult.putMap("documentLocation", SerializationUtils.serializeQuad(result.getDocumentLocation())); 44 | jsonResult.putString("faceImage", SerializationUtils.encodeImageBase64(result.getFaceImage())); 45 | jsonResult.putMap("faceLocation", SerializationUtils.serializeQuad(result.getFaceLocation())); 46 | jsonResult.putString("fullDocumentImage", SerializationUtils.encodeImageBase64(result.getFullDocumentImage())); 47 | return jsonResult; 48 | } 49 | 50 | @Override 51 | public String getJsonName() { 52 | return "DocumentFaceRecognizer"; 53 | } 54 | 55 | @Override 56 | public Class getRecognizerClass() { 57 | return com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceRecognizer.class; 58 | } 59 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/IdBarcodeRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 8 | import com.microblink.blinkid.reactnative.SerializationUtils; 9 | 10 | public final class IdBarcodeRecognizerSerialization implements RecognizerSerialization { 11 | @Override 12 | public Recognizer createRecognizer(ReadableMap jsonMap) { 13 | com.microblink.blinkid.entities.recognizers.blinkid.idbarcode.IdBarcodeRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkid.idbarcode.IdBarcodeRecognizer(); 14 | return recognizer; 15 | } 16 | 17 | @Override 18 | public WritableMap serializeResult(Recognizer recognizer) { 19 | com.microblink.blinkid.entities.recognizers.blinkid.idbarcode.IdBarcodeRecognizer.Result result = ((com.microblink.blinkid.entities.recognizers.blinkid.idbarcode.IdBarcodeRecognizer)recognizer).getResult(); 20 | WritableMap jsonResult = new WritableNativeMap(); 21 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 22 | jsonResult.putString("additionalNameInformation", result.getAdditionalNameInformation()); 23 | jsonResult.putString("address", result.getAddress()); 24 | jsonResult.putInt("age", result.getAge()); 25 | jsonResult.putInt("barcodeType", SerializationUtils.serializeEnum(result.getBarcodeType())); 26 | jsonResult.putString("city", result.getCity()); 27 | jsonResult.putMap("dateOfBirth", SerializationUtils.serializeDate(result.getDateOfBirth())); 28 | jsonResult.putMap("dateOfExpiry", SerializationUtils.serializeDate(result.getDateOfExpiry())); 29 | jsonResult.putMap("dateOfIssue", SerializationUtils.serializeDate(result.getDateOfIssue())); 30 | jsonResult.putString("documentAdditionalNumber", result.getDocumentAdditionalNumber()); 31 | jsonResult.putString("documentNumber", result.getDocumentNumber()); 32 | jsonResult.putInt("documentType", SerializationUtils.serializeEnum(result.getDocumentType())); 33 | jsonResult.putString("employer", result.getEmployer()); 34 | jsonResult.putString("endorsements", result.getEndorsements()); 35 | jsonResult.putBoolean("expired", result.isExpired()); 36 | jsonResult.putMap("extendedElements", BlinkIDSerializationUtils.serializeBarcodeElements(result.getExtendedElements())); 37 | jsonResult.putString("firstName", result.getFirstName()); 38 | jsonResult.putString("fullName", result.getFullName()); 39 | jsonResult.putString("issuingAuthority", result.getIssuingAuthority()); 40 | jsonResult.putString("jurisdiction", result.getJurisdiction()); 41 | jsonResult.putString("lastName", result.getLastName()); 42 | jsonResult.putString("maritalStatus", result.getMaritalStatus()); 43 | jsonResult.putString("middleName", result.getMiddleName()); 44 | jsonResult.putString("nationality", result.getNationality()); 45 | jsonResult.putString("personalIdNumber", result.getPersonalIdNumber()); 46 | jsonResult.putString("placeOfBirth", result.getPlaceOfBirth()); 47 | jsonResult.putString("postalCode", result.getPostalCode()); 48 | jsonResult.putString("profession", result.getProfession()); 49 | jsonResult.putString("race", result.getRace()); 50 | jsonResult.putString("rawData", SerializationUtils.encodeByteArrayToBase64(result.getRawData())); 51 | jsonResult.putString("religion", result.getReligion()); 52 | jsonResult.putString("residentialStatus", result.getResidentialStatus()); 53 | jsonResult.putString("restrictions", result.getRestrictions()); 54 | jsonResult.putString("sex", result.getSex()); 55 | jsonResult.putString("street", result.getStreet()); 56 | jsonResult.putString("stringData", result.getStringData()); 57 | jsonResult.putBoolean("uncertain", result.isUncertain()); 58 | jsonResult.putString("vehicleClass", result.getVehicleClass()); 59 | return jsonResult; 60 | } 61 | 62 | @Override 63 | public String getJsonName() { 64 | return "IdBarcodeRecognizer"; 65 | } 66 | 67 | @Override 68 | public Class getRecognizerClass() { 69 | return com.microblink.blinkid.entities.recognizers.blinkid.idbarcode.IdBarcodeRecognizer.class; 70 | } 71 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/MrtdCombinedRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 8 | import com.microblink.blinkid.reactnative.SerializationUtils; 9 | 10 | public final class MrtdCombinedRecognizerSerialization implements RecognizerSerialization { 11 | @Override 12 | public Recognizer createRecognizer(ReadableMap jsonMap) { 13 | com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdCombinedRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdCombinedRecognizer(); 14 | if (jsonMap.hasKey("allowSpecialCharacters")) { 15 | recognizer.setAllowSpecialCharacters(jsonMap.getBoolean("allowSpecialCharacters")); 16 | } 17 | if (jsonMap.hasKey("allowUnparsedResults")) { 18 | recognizer.setAllowUnparsedResults(jsonMap.getBoolean("allowUnparsedResults")); 19 | } 20 | if (jsonMap.hasKey("allowUnverifiedResults")) { 21 | recognizer.setAllowUnverifiedResults(jsonMap.getBoolean("allowUnverifiedResults")); 22 | } 23 | if (jsonMap.hasKey("detectorType")) { 24 | recognizer.setDetectorType(com.microblink.blinkid.entities.recognizers.blinkid.documentface.DocumentFaceDetectorType.values()[jsonMap.getInt("detectorType")]); 25 | } 26 | if (jsonMap.hasKey("faceImageDpi")) { 27 | recognizer.setFaceImageDpi(jsonMap.getInt("faceImageDpi")); 28 | } 29 | if (jsonMap.hasKey("fullDocumentImageDpi")) { 30 | recognizer.setFullDocumentImageDpi(jsonMap.getInt("fullDocumentImageDpi")); 31 | } 32 | if (jsonMap.hasKey("fullDocumentImageExtensionFactors")) { 33 | recognizer.setFullDocumentImageExtensionFactors(SerializationUtils.deserializeExtensionFactors(jsonMap.getMap("fullDocumentImageExtensionFactors"))); 34 | } 35 | if (jsonMap.hasKey("numStableDetectionsThreshold")) { 36 | recognizer.setNumStableDetectionsThreshold(jsonMap.getInt("numStableDetectionsThreshold")); 37 | } 38 | if (jsonMap.hasKey("returnFaceImage")) { 39 | recognizer.setReturnFaceImage(jsonMap.getBoolean("returnFaceImage")); 40 | } 41 | if (jsonMap.hasKey("returnFullDocumentImage")) { 42 | recognizer.setReturnFullDocumentImage(jsonMap.getBoolean("returnFullDocumentImage")); 43 | } 44 | return recognizer; 45 | } 46 | 47 | @Override 48 | public WritableMap serializeResult(Recognizer recognizer) { 49 | com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdCombinedRecognizer.Result result = ((com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdCombinedRecognizer)recognizer).getResult(); 50 | WritableMap jsonResult = new WritableNativeMap(); 51 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 52 | jsonResult.putInt("documentDataMatch", SerializationUtils.serializeEnum(result.getDocumentDataMatch())); 53 | jsonResult.putString("faceImage", SerializationUtils.encodeImageBase64(result.getFaceImage())); 54 | jsonResult.putString("fullDocumentBackImage", SerializationUtils.encodeImageBase64(result.getFullDocumentBackImage())); 55 | jsonResult.putString("fullDocumentFrontImage", SerializationUtils.encodeImageBase64(result.getFullDocumentFrontImage())); 56 | jsonResult.putMap("mrzResult", BlinkIDSerializationUtils.serializeMrzResult(result.getMrzResult())); 57 | jsonResult.putBoolean("scanningFirstSideDone", result.isScanningFirstSideDone()); 58 | return jsonResult; 59 | } 60 | 61 | @Override 62 | public String getJsonName() { 63 | return "MrtdCombinedRecognizer"; 64 | } 65 | 66 | @Override 67 | public Class getRecognizerClass() { 68 | return com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdCombinedRecognizer.class; 69 | } 70 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/MrtdRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 8 | import com.microblink.blinkid.reactnative.SerializationUtils; 9 | 10 | public final class MrtdRecognizerSerialization implements RecognizerSerialization { 11 | @Override 12 | public Recognizer createRecognizer(ReadableMap jsonMap) { 13 | com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdRecognizer(); 14 | if (jsonMap.hasKey("allowSpecialCharacters")) { 15 | recognizer.setAllowSpecialCharacters(jsonMap.getBoolean("allowSpecialCharacters")); 16 | } 17 | if (jsonMap.hasKey("allowUnparsedResults")) { 18 | recognizer.setAllowUnparsedResults(jsonMap.getBoolean("allowUnparsedResults")); 19 | } 20 | if (jsonMap.hasKey("allowUnverifiedResults")) { 21 | recognizer.setAllowUnverifiedResults(jsonMap.getBoolean("allowUnverifiedResults")); 22 | } 23 | if (jsonMap.hasKey("detectGlare")) { 24 | recognizer.setDetectGlare(jsonMap.getBoolean("detectGlare")); 25 | } 26 | if (jsonMap.hasKey("fullDocumentImageDpi")) { 27 | recognizer.setFullDocumentImageDpi(jsonMap.getInt("fullDocumentImageDpi")); 28 | } 29 | if (jsonMap.hasKey("fullDocumentImageExtensionFactors")) { 30 | recognizer.setFullDocumentImageExtensionFactors(SerializationUtils.deserializeExtensionFactors(jsonMap.getMap("fullDocumentImageExtensionFactors"))); 31 | } 32 | if (jsonMap.hasKey("returnFullDocumentImage")) { 33 | recognizer.setReturnFullDocumentImage(jsonMap.getBoolean("returnFullDocumentImage")); 34 | } 35 | return recognizer; 36 | } 37 | 38 | @Override 39 | public WritableMap serializeResult(Recognizer recognizer) { 40 | com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdRecognizer.Result result = ((com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdRecognizer)recognizer).getResult(); 41 | WritableMap jsonResult = new WritableNativeMap(); 42 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 43 | jsonResult.putString("fullDocumentImage", SerializationUtils.encodeImageBase64(result.getFullDocumentImage())); 44 | jsonResult.putMap("mrzResult", BlinkIDSerializationUtils.serializeMrzResult(result.getMrzResult())); 45 | return jsonResult; 46 | } 47 | 48 | @Override 49 | public String getJsonName() { 50 | return "MrtdRecognizer"; 51 | } 52 | 53 | @Override 54 | public Class getRecognizerClass() { 55 | return com.microblink.blinkid.entities.recognizers.blinkid.mrtd.MrtdRecognizer.class; 56 | } 57 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/PassportRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 8 | import com.microblink.blinkid.reactnative.SerializationUtils; 9 | 10 | public final class PassportRecognizerSerialization implements RecognizerSerialization { 11 | @Override 12 | public Recognizer createRecognizer(ReadableMap jsonMap) { 13 | com.microblink.blinkid.entities.recognizers.blinkid.passport.PassportRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkid.passport.PassportRecognizer(); 14 | if (jsonMap.hasKey("anonymizeNetherlandsMrz")) { 15 | recognizer.setAnonymizeNetherlandsMrz(jsonMap.getBoolean("anonymizeNetherlandsMrz")); 16 | } 17 | if (jsonMap.hasKey("detectGlare")) { 18 | recognizer.setDetectGlare(jsonMap.getBoolean("detectGlare")); 19 | } 20 | if (jsonMap.hasKey("faceImageDpi")) { 21 | recognizer.setFaceImageDpi(jsonMap.getInt("faceImageDpi")); 22 | } 23 | if (jsonMap.hasKey("fullDocumentImageDpi")) { 24 | recognizer.setFullDocumentImageDpi(jsonMap.getInt("fullDocumentImageDpi")); 25 | } 26 | if (jsonMap.hasKey("fullDocumentImageExtensionFactors")) { 27 | recognizer.setFullDocumentImageExtensionFactors(SerializationUtils.deserializeExtensionFactors(jsonMap.getMap("fullDocumentImageExtensionFactors"))); 28 | } 29 | if (jsonMap.hasKey("returnFaceImage")) { 30 | recognizer.setReturnFaceImage(jsonMap.getBoolean("returnFaceImage")); 31 | } 32 | if (jsonMap.hasKey("returnFullDocumentImage")) { 33 | recognizer.setReturnFullDocumentImage(jsonMap.getBoolean("returnFullDocumentImage")); 34 | } 35 | return recognizer; 36 | } 37 | 38 | @Override 39 | public WritableMap serializeResult(Recognizer recognizer) { 40 | com.microblink.blinkid.entities.recognizers.blinkid.passport.PassportRecognizer.Result result = ((com.microblink.blinkid.entities.recognizers.blinkid.passport.PassportRecognizer)recognizer).getResult(); 41 | WritableMap jsonResult = new WritableNativeMap(); 42 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 43 | jsonResult.putString("faceImage", SerializationUtils.encodeImageBase64(result.getFaceImage())); 44 | jsonResult.putString("fullDocumentImage", SerializationUtils.encodeImageBase64(result.getFullDocumentImage())); 45 | jsonResult.putMap("mrzResult", BlinkIDSerializationUtils.serializeMrzResult(result.getMrzResult())); 46 | return jsonResult; 47 | } 48 | 49 | @Override 50 | public String getJsonName() { 51 | return "PassportRecognizer"; 52 | } 53 | 54 | @Override 55 | public Class getRecognizerClass() { 56 | return com.microblink.blinkid.entities.recognizers.blinkid.passport.PassportRecognizer.class; 57 | } 58 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/SuccessFrameGrabberRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.entities.recognizers.successframe.SuccessFrameGrabberRecognizer; 8 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 9 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerializers; 10 | import com.microblink.blinkid.reactnative.SerializationUtils; 11 | 12 | public final class SuccessFrameGrabberRecognizerSerialization implements RecognizerSerialization { 13 | @Override 14 | public Recognizer createRecognizer(ReadableMap jsonRecognizer) { 15 | // first obtain slave recognizer 16 | ReadableMap jsonSlaveRecognizer = jsonRecognizer.getMap("slaveRecognizer"); 17 | Recognizer slaveRecognizer = RecognizerSerializers.INSTANCE.getRecognizerSerialization(jsonSlaveRecognizer).createRecognizer(jsonSlaveRecognizer); 18 | return new SuccessFrameGrabberRecognizer(slaveRecognizer); 19 | } 20 | 21 | @Override 22 | public WritableMap serializeResult(Recognizer recognizer) { 23 | SuccessFrameGrabberRecognizer sfgr = (SuccessFrameGrabberRecognizer) recognizer; 24 | WritableMap jsonSlaveResult = RecognizerSerializers.INSTANCE.getRecognizerSerialization(sfgr.getSlaveRecognizer()).serializeResult(sfgr.getSlaveRecognizer()); 25 | 26 | SuccessFrameGrabberRecognizer.Result result = sfgr.getResult(); 27 | 28 | WritableMap jsonResult = new WritableNativeMap(); 29 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 30 | jsonResult.putMap("slaveRecognizerResult", jsonSlaveResult); 31 | jsonResult.putString("successFrame", SerializationUtils.encodeImageBase64(result.getSuccessFrame())); 32 | 33 | return jsonResult; 34 | } 35 | 36 | @Override 37 | public String getJsonName() { 38 | return "SuccessFrameGrabberRecognizer"; 39 | } 40 | 41 | @Override 42 | public Class getRecognizerClass() { 43 | return SuccessFrameGrabberRecognizer.class; 44 | } 45 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/UsdlCombinedRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableArray; 5 | import com.facebook.react.bridge.WritableMap; 6 | import com.facebook.react.bridge.WritableNativeArray; 7 | import com.facebook.react.bridge.WritableNativeMap; 8 | import com.microblink.blinkid.entities.recognizers.Recognizer; 9 | import com.microblink.blinkid.entities.recognizers.blinkid.usdl.UsdlCombinedRecognizer; 10 | import com.microblink.blinkid.entities.recognizers.blinkbarcode.usdl.UsdlKeys; 11 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 12 | import com.microblink.blinkid.reactnative.SerializationUtils; 13 | 14 | public final class UsdlCombinedRecognizerSerialization implements RecognizerSerialization { 15 | @Override 16 | public Recognizer createRecognizer(ReadableMap jsonRecognizer) { 17 | UsdlCombinedRecognizer recognizer = new UsdlCombinedRecognizer(); 18 | if (jsonRecognizer.hasKey("faceImageDpi")) { 19 | recognizer.setFaceImageDpi(jsonRecognizer.getInt("faceImageDpi")); 20 | } 21 | if (jsonRecognizer.hasKey("fullDocumentImageDpi")) { 22 | recognizer.setFullDocumentImageDpi(jsonRecognizer.getInt("fullDocumentImageDpi")); 23 | } 24 | if (jsonRecognizer.hasKey("fullDocumentImageExtensionFactors")) { 25 | recognizer.setFullDocumentImageExtensionFactors(SerializationUtils.deserializeExtensionFactors(jsonRecognizer.getMap("fullDocumentImageExtensionFactors"))); 26 | } 27 | if (jsonRecognizer.hasKey("numStableDetectionsThreshold")) { 28 | recognizer.setNumStableDetectionsThreshold(jsonRecognizer.getInt("numStableDetectionsThreshold")); 29 | } 30 | if (jsonRecognizer.hasKey("returnFaceImage")) { 31 | recognizer.setReturnFaceImage(jsonRecognizer.getBoolean("returnFaceImage")); 32 | } 33 | if (jsonRecognizer.hasKey("returnFullDocumentImage")) { 34 | recognizer.setReturnFullDocumentImage(jsonRecognizer.getBoolean("returnFullDocumentImage")); 35 | } 36 | return recognizer; 37 | } 38 | 39 | @Override 40 | public WritableMap serializeResult(Recognizer recognizer) { 41 | UsdlCombinedRecognizer.Result result = ((UsdlCombinedRecognizer)recognizer).getResult(); 42 | WritableMap jsonResult = new WritableNativeMap(); 43 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 44 | jsonResult.putInt("documentDataMatch", SerializationUtils.serializeEnum(result.getDocumentDataMatch())); 45 | jsonResult.putString("faceImage", SerializationUtils.encodeImageBase64(result.getFaceImage())); 46 | jsonResult.putString("fullDocumentImage", SerializationUtils.encodeImageBase64(result.getFullDocumentImage())); 47 | jsonResult.putBoolean("scanningFirstSideDone", result.isScanningFirstSideDone()); 48 | 49 | jsonResult.putArray("optionalElements", SerializationUtils.serializeStringArray(result.getOptionalElements())); 50 | jsonResult.putString("rawData", SerializationUtils.encodeByteArrayToBase64(result.getRawData())); 51 | jsonResult.putString("rawStringData", result.getRawStringData()); 52 | jsonResult.putBoolean("uncertain", result.isUncertain()); 53 | jsonResult.putArray("fields", serializeFields(result)); 54 | jsonResult.putString("firstName", result.getFirstName()); 55 | jsonResult.putString("lastName", result.getLastName()); 56 | jsonResult.putString("fullName", result.getFullName()); 57 | jsonResult.putString("middleName", result.getMiddleName()); 58 | jsonResult.putString("nameSuffix", result.getNameSuffix()); 59 | jsonResult.putString("address", result.getAddress()); 60 | jsonResult.putString("documentNumber", result.getDocumentNumber()); 61 | jsonResult.putString("sex", result.getSex()); 62 | jsonResult.putInt("age", result.getAge()); 63 | jsonResult.putString("restrictions", result.getRestrictions()); 64 | jsonResult.putString("endorsements", result.getEndorsements()); 65 | jsonResult.putString("vehicleClass", result.getVehicleClass()); 66 | jsonResult.putMap("dateOfBirth", SerializationUtils.serializeDate(result.getDateOfBirth())); 67 | jsonResult.putMap("dateOfIssue", SerializationUtils.serializeDate(result.getDateOfIssue())); 68 | jsonResult.putMap("dateOfExpiry", SerializationUtils.serializeDate(result.getDateOfExpiry())); 69 | 70 | return jsonResult; 71 | } 72 | 73 | private WritableArray serializeFields(UsdlCombinedRecognizer.Result result) { 74 | WritableArray fieldsArr = new WritableNativeArray(); 75 | for (int i = 0; i < UsdlKeys.values().length; ++i) { 76 | fieldsArr.pushString(result.getField(UsdlKeys.values()[i])); 77 | } 78 | return fieldsArr; 79 | } 80 | 81 | @Override 82 | public String getJsonName() { 83 | return "UsdlCombinedRecognizer"; 84 | } 85 | 86 | @Override 87 | public Class getRecognizerClass() { 88 | return com.microblink.blinkid.entities.recognizers.blinkid.usdl.UsdlCombinedRecognizer.class; 89 | } 90 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/UsdlRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableArray; 5 | import com.facebook.react.bridge.WritableMap; 6 | import com.facebook.react.bridge.WritableNativeArray; 7 | import com.facebook.react.bridge.WritableNativeMap; 8 | import com.microblink.blinkid.entities.recognizers.Recognizer; 9 | import com.microblink.blinkid.entities.recognizers.blinkbarcode.usdl.UsdlKeys; 10 | import com.microblink.blinkid.entities.recognizers.blinkbarcode.usdl.UsdlRecognizer; 11 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 12 | import com.microblink.blinkid.reactnative.SerializationUtils; 13 | 14 | public final class UsdlRecognizerSerialization implements RecognizerSerialization { 15 | @Override 16 | public Recognizer createRecognizer(ReadableMap jsonRecognizer) { 17 | com.microblink.blinkid.entities.recognizers.blinkbarcode.usdl.UsdlRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkbarcode.usdl.UsdlRecognizer(); 18 | if (jsonRecognizer.hasKey("nullQuietZoneAllowed")) { 19 | recognizer.setNullQuietZoneAllowed(jsonRecognizer.getBoolean("nullQuietZoneAllowed")); 20 | } 21 | if (jsonRecognizer.hasKey("uncertainDecoding")) { 22 | recognizer.setUncertainDecoding(jsonRecognizer.getBoolean("uncertainDecoding")); 23 | } 24 | return recognizer; 25 | } 26 | 27 | @Override 28 | public WritableMap serializeResult(Recognizer recognizer) { 29 | UsdlRecognizer.Result result = ((UsdlRecognizer)recognizer).getResult(); 30 | WritableMap jsonResult = new WritableNativeMap(); 31 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 32 | jsonResult.putArray("optionalElements", SerializationUtils.serializeStringArray(result.getOptionalElements())); 33 | jsonResult.putString("rawData", SerializationUtils.encodeByteArrayToBase64(result.getRawData())); 34 | jsonResult.putString("rawStringData", result.getRawStringData()); 35 | jsonResult.putBoolean("uncertain", result.isUncertain()); 36 | jsonResult.putArray("fields", serializeFields(result)); 37 | jsonResult.putString("firstName", result.getFirstName()); 38 | jsonResult.putString("lastName", result.getLastName()); 39 | jsonResult.putString("fullName", result.getFullName()); 40 | jsonResult.putString("middleName", result.getMiddleName()); 41 | jsonResult.putString("nameSuffix", result.getNameSuffix()); 42 | jsonResult.putString("address", result.getAddress()); 43 | jsonResult.putString("documentNumber", result.getDocumentNumber()); 44 | jsonResult.putString("sex", result.getSex()); 45 | jsonResult.putInt("age", result.getAge()); 46 | jsonResult.putString("restrictions", result.getRestrictions()); 47 | jsonResult.putString("endorsements", result.getEndorsements()); 48 | jsonResult.putString("vehicleClass", result.getVehicleClass()); 49 | jsonResult.putMap("dateOfBirth", SerializationUtils.serializeDate(result.getDateOfBirth())); 50 | jsonResult.putMap("dateOfIssue", SerializationUtils.serializeDate(result.getDateOfIssue())); 51 | jsonResult.putMap("dateOfExpiry", SerializationUtils.serializeDate(result.getDateOfExpiry())); 52 | 53 | return jsonResult; 54 | } 55 | 56 | private WritableArray serializeFields(UsdlRecognizer.Result result) { 57 | WritableArray fieldsArr = new WritableNativeArray(); 58 | for (int i = 0; i < UsdlKeys.values().length; ++i) { 59 | fieldsArr.pushString(result.getField(UsdlKeys.values()[i])); 60 | } 61 | return fieldsArr; 62 | } 63 | 64 | @Override 65 | public String getJsonName() { 66 | return "UsdlRecognizer"; 67 | } 68 | 69 | @Override 70 | public Class getRecognizerClass() { 71 | return com.microblink.blinkid.entities.recognizers.blinkbarcode.usdl.UsdlRecognizer.class; 72 | } 73 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/java/com/microblink/blinkid/reactnative/recognizers/serialization/VisaRecognizerSerialization.java: -------------------------------------------------------------------------------- 1 | package com.microblink.blinkid.reactnative.recognizers.serialization; 2 | 3 | import com.facebook.react.bridge.ReadableMap; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.bridge.WritableNativeMap; 6 | import com.microblink.blinkid.entities.recognizers.Recognizer; 7 | import com.microblink.blinkid.reactnative.recognizers.RecognizerSerialization; 8 | import com.microblink.blinkid.reactnative.SerializationUtils; 9 | 10 | public final class VisaRecognizerSerialization implements RecognizerSerialization { 11 | @Override 12 | public Recognizer createRecognizer(ReadableMap jsonMap) { 13 | com.microblink.blinkid.entities.recognizers.blinkid.visa.VisaRecognizer recognizer = new com.microblink.blinkid.entities.recognizers.blinkid.visa.VisaRecognizer(); 14 | if (jsonMap.hasKey("detectGlare")) { 15 | recognizer.setDetectGlare(jsonMap.getBoolean("detectGlare")); 16 | } 17 | if (jsonMap.hasKey("faceImageDpi")) { 18 | recognizer.setFaceImageDpi(jsonMap.getInt("faceImageDpi")); 19 | } 20 | if (jsonMap.hasKey("fullDocumentImageDpi")) { 21 | recognizer.setFullDocumentImageDpi(jsonMap.getInt("fullDocumentImageDpi")); 22 | } 23 | if (jsonMap.hasKey("fullDocumentImageExtensionFactors")) { 24 | recognizer.setFullDocumentImageExtensionFactors(SerializationUtils.deserializeExtensionFactors(jsonMap.getMap("fullDocumentImageExtensionFactors"))); 25 | } 26 | if (jsonMap.hasKey("returnFaceImage")) { 27 | recognizer.setReturnFaceImage(jsonMap.getBoolean("returnFaceImage")); 28 | } 29 | if (jsonMap.hasKey("returnFullDocumentImage")) { 30 | recognizer.setReturnFullDocumentImage(jsonMap.getBoolean("returnFullDocumentImage")); 31 | } 32 | return recognizer; 33 | } 34 | 35 | @Override 36 | public WritableMap serializeResult(Recognizer recognizer) { 37 | com.microblink.blinkid.entities.recognizers.blinkid.visa.VisaRecognizer.Result result = ((com.microblink.blinkid.entities.recognizers.blinkid.visa.VisaRecognizer)recognizer).getResult(); 38 | WritableMap jsonResult = new WritableNativeMap(); 39 | SerializationUtils.addCommonRecognizerResultData(jsonResult, result); 40 | jsonResult.putString("faceImage", SerializationUtils.encodeImageBase64(result.getFaceImage())); 41 | jsonResult.putString("fullDocumentImage", SerializationUtils.encodeImageBase64(result.getFullDocumentImage())); 42 | jsonResult.putMap("mrzResult", BlinkIDSerializationUtils.serializeMrzResult(result.getMrzResult())); 43 | return jsonResult; 44 | } 45 | 46 | @Override 47 | public String getJsonName() { 48 | return "VisaRecognizer"; 49 | } 50 | 51 | @Override 52 | public Class getRecognizerClass() { 53 | return com.microblink.blinkid.entities.recognizers.blinkid.visa.VisaRecognizer.class; 54 | } 55 | } -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/res/layout/mb_layout_camera_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /BlinkID/src/android/src/main/res/raw/beep.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlinkID/blinkid-react-native/c6b53a7d7b40e06f6c470cdb470f1ee8c3c0100e/BlinkID/src/android/src/main/res/raw/beep.mp3 -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule.xcodeproj/project.xcworkspace/xcuserdata/juraskrlec.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlinkID/blinkid-react-native/c6b53a7d7b40e06f6c470cdb470f1ee8c3c0100e/BlinkID/src/ios/MicroblinkModule/MicroblinkModule.xcodeproj/project.xcworkspace/xcuserdata/juraskrlec.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/MBBlinkIDModule.h: -------------------------------------------------------------------------------- 1 | // 2 | // BlinkIDReactNative.h 3 | // BlinkIDReactNative 4 | // 5 | // Created by Jura Skrlec on 12/04/2017. 6 | // Copyright © 2017 Microblink. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MBBlinkIDModule : NSObject 12 | 13 | 14 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/MBBlinkIDSerializationUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBBlinkIDSerializationUtils.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import 9 | 10 | #import 11 | 12 | @interface MBBlinkIDSerializationUtils : NSObject 13 | 14 | +(NSDictionary * _Nonnull) serializeMrzResult:(MBMrzResult * _Nonnull)mrzResult; 15 | +(MBImageExtensionFactors) deserializeMBImageExtensionFactors:(NSDictionary * _Nullable)jsonExtensionFactors; 16 | +(NSDictionary * _Nonnull) serializeDriverLicenseDetailedInfo:(MBDriverLicenseDetailedInfo * _Nonnull)driverLicenseDetailedInfo; 17 | +(NSDictionary * _Nonnull) serializeBarcodeDriverLicenseDetailedInfo:(MBBarcodeDriverLicenseDetailedInfo * _Nonnull)driverLicenseDetailedInfo; 18 | +(NSDictionary * _Nonnull) serializeDataMatchResult:(MBDataMatchResult * _Nonnull)dataMatchResult; 19 | +(NSDictionary * _Nonnull) serializeFieldState:(MBFieldState * _Nonnull)fieldState; 20 | +(NSDictionary * _Nonnull) serializeClassInfo:(MBClassInfo * _Nonnull)classInfo; 21 | +(NSDictionary * _Nonnull) serializeVizResult:(MBVizResult * _Nonnull)vizResult; 22 | +(NSDictionary * _Nonnull) serializeBarcodeResult:(MBBarcodeResult * _Nonnull)barcodeResult; 23 | +(NSDictionary * _Nonnull) serializeImageAnalysisResult:(MBImageAnalysisResult * _Nonnull)imageAnalysisResult; 24 | +(MBRecognitionModeFilter * _Nonnull) deserializeMBRecognitionModeFilter:(NSDictionary * _Nullable)jsonRecognitionModeFilter; 25 | +(MBClassAnonymizationSettings * _Nonnull) deserializeMBClassAnonymizationSettings:(NSDictionary * _Nullable)jsonClassAnonymizationSettings; 26 | +(NSDictionary * _Nonnull) serializeBarcodeElements:(MBBarcodeElements * _Nonnull)extendedElements; 27 | +(NSArray * _Nonnull) serializeBarcodeElementsValues:(MBBarcodeElements * _Nonnull)extendedElements; 28 | + (NSDictionary * _Nonnull)serializeAdditionalProcessingInfo:(MBAdditionalProcessingInfo * _Nullable)additionalProcessingInfo; 29 | + (NSDictionary * _Nonnull)serializeMBDateResult:(MBDateResult * _Nullable) value; 30 | +(NSDictionary * _Nonnull) serializeMBStringResult:(MBStringResult * _Nullable) value; 31 | +(NSNumber * _Nullable)serializeMBSide:(MBSide) value; 32 | +(NSDictionary * _Nonnull) serializeNSDate:(NSDate * _Nullable) value; 33 | +(MBCustomClassRules * _Nonnull) deserializeMBCustomClassRules:(NSDictionary * _Nullable)jsonCustomClassRules; 34 | +(NSMutableArray * _Nullable) serializeDependentInfo:(NSArray* _Nullable)dependentInfos; 35 | + (BOOL)deserializeClassFilter:(NSDictionary * _Nullable)jsonRecognizerCollection classInfo:(MBClassInfo * _Nullable)classInfo; 36 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/MBCommonSerializationUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBBlinkIDSerializationUtils.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import 9 | 10 | #import 11 | 12 | @interface MBCommonSerializationUtils : NSObject 13 | 14 | +(MBImageExtensionFactors) deserializeMBImageExtensionFactors:(NSDictionary * _Nullable)jsonExtensionFactors; 15 | 16 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/MBCommonSerializationUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBBlinkIDSerializationUtils.m 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBCommonSerializationUtils.h" 9 | #import "MBSerializationUtils.h" 10 | 11 | @implementation MBCommonSerializationUtils 12 | 13 | +(MBImageExtensionFactors) deserializeMBImageExtensionFactors:(NSDictionary *)jsonExtensionFactors { 14 | if (jsonExtensionFactors == nil) { 15 | return MBMakeImageExtensionFactors(0.f, 0.f, 0.f, 0.f); 16 | } else { 17 | return MBMakeImageExtensionFactors( 18 | [(NSNumber*)[jsonExtensionFactors valueForKey:@"upFactor"] floatValue], 19 | [(NSNumber*)[jsonExtensionFactors valueForKey:@"rightFactor"] floatValue], 20 | [(NSNumber*)[jsonExtensionFactors valueForKey:@"downFactor"] floatValue], 21 | [(NSNumber*)[jsonExtensionFactors valueForKey:@"leftFactor"] floatValue] 22 | ); 23 | } 24 | } 25 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/MBSerializationUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBSerializationUtils.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 01/06/2018. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | @interface MBSerializationUtils : NSObject 12 | 13 | +(NSDictionary * _Nonnull) serializeMBDate:(MBDate * _Nonnull) date; 14 | +(NSString * _Nullable) encodeMBImage:(MBImage * _Nullable) image; 15 | +(NSDictionary * _Nonnull)serializeCGPoint:(CGPoint) point; 16 | +(NSDictionary * _Nonnull) serializeMBQuadrangle:(MBQuadrangle * _Nonnull) quad; 17 | +(NSDictionary * _Nonnull)serializeCGRect:(CGRect) rect; 18 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/MBSerializationUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBSerializationUtils.m 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 01/06/2018. 6 | // 7 | 8 | #import "MBSerializationUtils.h" 9 | 10 | @implementation MBSerializationUtils 11 | 12 | + (NSDictionary *)serializeMBDate:(MBDate *) date { 13 | return @{ 14 | @"day" : @(date.day), 15 | @"month" : @(date.month), 16 | @"year" : @(date.year), 17 | @"originalDateString" : date.originalDateString, 18 | @"isFilledByDomainKnowledge" : [NSNumber numberWithBool:date.isFilledByDomainKnowledge], 19 | }; 20 | } 21 | 22 | +(NSString *) encodeMBImage:(MBImage * _Nullable) image { 23 | const int COMPRESSED_IMAGE_QUALITY = 90; 24 | 25 | if (image != nil) { 26 | NSData *imageData = UIImageJPEGRepresentation(image.image, COMPRESSED_IMAGE_QUALITY / 100.f); 27 | return [imageData base64EncodedStringWithOptions:0]; 28 | } else { 29 | return nil; 30 | } 31 | } 32 | 33 | +(NSDictionary *)serializeCGPoint:(CGPoint) point { 34 | return @{ 35 | @"x" : [NSNumber numberWithFloat:point.x], 36 | @"y" : [NSNumber numberWithFloat:point.y] 37 | }; 38 | } 39 | 40 | +(NSDictionary *) serializeMBQuadrangle:(MBQuadrangle *) quad { 41 | return @{ 42 | @"upperLeft" : [MBSerializationUtils serializeCGPoint:quad.upperLeft], 43 | @"upperRight" : [MBSerializationUtils serializeCGPoint:quad.upperRight], 44 | @"lowerLeft" : [MBSerializationUtils serializeCGPoint:quad.lowerLeft], 45 | @"lowerRight" : [MBSerializationUtils serializeCGPoint:quad.lowerRight] 46 | }; 47 | } 48 | 49 | +(NSDictionary *)serializeCGRect:(CGRect) rect { 50 | NSDictionary *rectDictionaty = [NSDictionary new]; 51 | if (!CGRectIsNull(rect)) { 52 | rectDictionaty = @{ 53 | @"x" : [NSNumber numberWithFloat:rect.origin.x], 54 | @"y" : [NSNumber numberWithFloat:rect.origin.y], 55 | @"height": [NSNumber numberWithFloat:rect.size.height], 56 | @"width": [NSNumber numberWithFloat:rect.size.width], 57 | }; 58 | } 59 | return rectDictionaty; 60 | } 61 | 62 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/MBOverlaySerializationUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBOverlaySerializationUtils.h 3 | // MicroblinkModule 4 | // 5 | // Created by DoDo on 08/06/2018. 6 | // Copyright © 2018 Jura Skrlec. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface MBOverlaySerializationUtils : NSObject 13 | 14 | +(void) extractCommonOverlaySettings:(NSDictionary *)jsonOverlaySettings overlaySettings:(MBOverlaySettings *)overlaySettings; 15 | 16 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/MBOverlaySerializationUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBOverlaySerializationUtils.m 3 | // MicroblinkModule 4 | // 5 | // Created by DoDo on 08/06/2018. 6 | // Copyright © 2018 Jura Skrlec. All rights reserved. 7 | // 8 | 9 | #import "MBOverlaySerializationUtils.h" 10 | 11 | @implementation MBOverlaySerializationUtils 12 | 13 | +(void) extractCommonOverlaySettings:(NSDictionary *)jsonOverlaySettings overlaySettings:(MBOverlaySettings *)overlaySettings { 14 | { 15 | id useFrontCamera = [jsonOverlaySettings objectForKey:@"useFrontCamera"]; 16 | if (useFrontCamera != nil && [(NSNumber*)useFrontCamera boolValue]) { 17 | overlaySettings.cameraSettings.cameraType = MBCameraTypeFront; 18 | } 19 | } 20 | { 21 | id language = [jsonOverlaySettings objectForKey:@"language"]; 22 | if (language != nil && language != NSNull.null) { 23 | id country = [jsonOverlaySettings objectForKey:@"country"]; 24 | if (country && country != NSNull.null) { 25 | overlaySettings.language = [[(NSString *)language stringByAppendingString:@"-" ] stringByAppendingString:(NSString *)country]; 26 | } else { 27 | overlaySettings.language = (NSString *)language; 28 | } 29 | } 30 | } 31 | if ([overlaySettings isKindOfClass:[MBBaseOverlaySettings class]]) { 32 | MBBaseOverlaySettings *baseOverlaySettings = (MBBaseOverlaySettings*)overlaySettings; 33 | { 34 | id enableBeep = [jsonOverlaySettings objectForKey:@"enableBeep"]; 35 | if ([enableBeep isKindOfClass:NSNumber.class]) { 36 | if (((NSNumber*)enableBeep).boolValue) { 37 | baseOverlaySettings.soundFilePath = [[MBMicroblinkApp sharedInstance].resourcesBundle pathForResource:@"PPbeep" ofType:@"wav"]; 38 | } else { 39 | baseOverlaySettings.soundFilePath = @""; 40 | } 41 | } 42 | } 43 | } 44 | } 45 | 46 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/MBOverlaySettingsSerializers.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBOverlaySettingsSerializers.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBOverlayViewControllerDelegate.h" 9 | 10 | #import 11 | 12 | #import 13 | 14 | @interface MBOverlaySettingsSerializers : NSObject 15 | 16 | +(instancetype) sharedInstance; 17 | 18 | -(MBOverlayViewController *) createOverlayViewController:(NSDictionary *)jsonOverlaySettings recognizerCollection:(MBRecognizerCollection*)recognizerCollection delegate:(id)delegate; 19 | 20 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/MBOverlaySettingsSerializers.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBOverlaySettingsSerializers.m 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBOverlaySettingsSerializers.h" 9 | 10 | #import "MBOverlayVCCreator.h" 11 | #import "MBDocumentOverlaySettingsSerialization.h" 12 | #import "MBDocumentVerificationOverlaySettingsSerialization.h" 13 | #import "MBBlinkIdOverlaySettingsSerialization.h" 14 | 15 | @interface MBOverlaySettingsSerializers () 16 | 17 | @property (nonatomic, strong) NSDictionary> *overlayCreators; 18 | 19 | @end 20 | 21 | @implementation MBOverlaySettingsSerializers 22 | 23 | - (void)registerMapping:(id)overlayCreator { 24 | [self.overlayCreators setValue:overlayCreator forKey:overlayCreator.jsonName]; 25 | } 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | if (self) { 30 | _overlayCreators = [[NSMutableDictionary alloc] init]; 31 | [self registerMapping:[[MBDocumentOverlaySettingsSerialization alloc] init]]; 32 | [self registerMapping:[[MBDocumentVerificationOverlaySettingsSerialization alloc] init]]; 33 | [self registerMapping:[[MBBlinkIdOverlaySettingsSerialization alloc] init]]; 34 | } 35 | return self; 36 | } 37 | 38 | + (instancetype)sharedInstance { 39 | static MBOverlaySettingsSerializers *sharedInstance = nil; 40 | static dispatch_once_t onceToken; 41 | dispatch_once(&onceToken, ^{ 42 | sharedInstance = [[self alloc] init]; 43 | 44 | }); 45 | return sharedInstance; 46 | } 47 | 48 | -(MBOverlayViewController *) createOverlayViewController:(NSDictionary *)jsonOverlaySettings recognizerCollection:(MBRecognizerCollection*)recognizerCollection delegate:(id)delegate { 49 | return [[self.overlayCreators valueForKey:[jsonOverlaySettings valueForKey:@"overlaySettingsType"]] createOverlayViewController:jsonOverlaySettings recognizerCollection:recognizerCollection delegate:delegate]; 50 | } 51 | 52 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/MBOverlayVCCreator.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBOverlayVCCreator.h 3 | // 4 | // Created by DoDo on 08/06/2018. 5 | // Copyright © 2018 Microblink. All rights reserved. 6 | // 7 | 8 | #pragma once 9 | 10 | #import "MBOverlayViewControllerDelegate.h" 11 | 12 | #import 13 | #import 14 | 15 | @protocol MBOverlayVCCreator 16 | @required 17 | 18 | - (MBOverlayViewController * _Nullable)createOverlayViewController:(NSDictionary * _Nullable)jsonOverlaySettings recognizerCollection:(MBRecognizerCollection * _Nullable)recognizerCollection delegate:(id _Nullable) delegate; 19 | 20 | @property (nonatomic, nonnull, readonly) NSString *jsonName; 21 | 22 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/MBOverlayViewControllerDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBOverlayViewControllerDelegate.h 3 | // 4 | // Created by DoDo on 01/06/2018. 5 | // 6 | 7 | #pragma once 8 | 9 | #import 10 | 11 | @protocol MBOverlayViewControllerDelegate 12 | @required 13 | 14 | - (void)overlayViewControllerDidFinishScanning:(MBOverlayViewController *)overlayViewController state:(MBRecognizerResultState)state; 15 | - (void)overlayDidTapClose:(MBOverlayViewController *)overlayViewController; 16 | 17 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/Serialization/MBBlinkIdOverlaySettingsSerialization.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBBlinkCardOverlaySettingsSerialization.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBOverlayVCCreator.h" 9 | 10 | #import 11 | 12 | @interface MBBlinkIdOverlaySettingsSerialization : NSObject 13 | 14 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/Serialization/MBBlinkIdOverlaySettingsSerialization.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBBlinkIdOverlaySettingsSerialization.m 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBBlinkIdOverlaySettingsSerialization.h" 9 | #import "MBOverlaySerializationUtils.h" 10 | 11 | @interface MBBlinkIdOverlaySettingsSerialization () 12 | 13 | @property (nonatomic, weak) id delegate; 14 | 15 | @end 16 | 17 | @implementation MBBlinkIdOverlaySettingsSerialization 18 | 19 | @synthesize jsonName = _jsonName; 20 | 21 | -(instancetype) init { 22 | self = [super init]; 23 | if (self) { 24 | _jsonName = @"BlinkIdOverlaySettings"; 25 | } 26 | return self; 27 | } 28 | 29 | -(MBOverlayViewController *) createOverlayViewController:(NSDictionary *)jsonOverlaySettings recognizerCollection:(MBRecognizerCollection*)recognizerCollection delegate:(id) delegate { 30 | // no settings deserialized at the moment 31 | MBBlinkIdOverlaySettings *sett = [[MBBlinkIdOverlaySettings alloc] init]; 32 | self.delegate = delegate; 33 | [MBOverlaySerializationUtils extractCommonOverlaySettings:jsonOverlaySettings overlaySettings:sett]; 34 | 35 | { 36 | id requireDocumentSidesDataMatch = [jsonOverlaySettings valueForKey:@"requireDocumentSidesDataMatch"]; 37 | if (requireDocumentSidesDataMatch != nil) { 38 | sett.requireDocumentSidesDataMatch = [requireDocumentSidesDataMatch boolValue]; 39 | } 40 | } 41 | 42 | { 43 | id showNotSupportedDialog = [jsonOverlaySettings valueForKey:@"showNotSupportedDialog"]; 44 | if (showNotSupportedDialog != nil) { 45 | sett.showNotSupportedDialog = [showNotSupportedDialog boolValue]; 46 | } 47 | } 48 | 49 | { 50 | id showFlashlightWarning = [jsonOverlaySettings valueForKey:@"showFlashlightWarning"]; 51 | if (showFlashlightWarning != nil) { 52 | sett.showFlashlightWarning = [showFlashlightWarning boolValue]; 53 | } 54 | } 55 | 56 | { 57 | id backSideScanningTimeoutMilliseconds = [jsonOverlaySettings valueForKey:@"backSideScanningTimeoutMilliseconds"]; 58 | if (backSideScanningTimeoutMilliseconds != nil) { 59 | sett.backSideScanningTimeout = [backSideScanningTimeoutMilliseconds doubleValue] / 1000.0; 60 | } 61 | } 62 | 63 | { 64 | id firstSideInstructionsText = [jsonOverlaySettings valueForKey:@"firstSideInstructionsText"]; 65 | if (firstSideInstructionsText != nil) { 66 | sett.firstSideInstructionsText = (NSString *)firstSideInstructionsText; 67 | } 68 | } 69 | 70 | { 71 | id flipInstructions = [jsonOverlaySettings valueForKey:@"flipInstructions"]; 72 | if (flipInstructions != nil) { 73 | sett.flipInstructions = (NSString *)flipInstructions; 74 | } 75 | } 76 | 77 | { 78 | id errorMoveCloser = [jsonOverlaySettings valueForKey:@"errorMoveCloser"]; 79 | if (errorMoveCloser != nil) { 80 | sett.errorMoveCloser = (NSString *)errorMoveCloser; 81 | } 82 | } 83 | 84 | { 85 | id errorMoveFarther = [jsonOverlaySettings valueForKey:@"errorMoveFarther"]; 86 | if (errorMoveFarther != nil) { 87 | sett.errorMoveFarther = (NSString *)errorMoveFarther; 88 | } 89 | } 90 | 91 | { 92 | id sidesNotMatchingTitle = [jsonOverlaySettings valueForKey:@"sidesNotMatchingTitle"]; 93 | if (sidesNotMatchingTitle != nil) { 94 | sett.sidesNotMatchingTitle = (NSString *)sidesNotMatchingTitle; 95 | } 96 | } 97 | 98 | { 99 | id sidesNotMatchingMessage = [jsonOverlaySettings valueForKey:@"sidesNotMatchingMessage"]; 100 | if (sidesNotMatchingMessage != nil) { 101 | sett.sidesNotMatchingMessage = (NSString *)sidesNotMatchingMessage; 102 | } 103 | } 104 | 105 | { 106 | id dataMismatchTitle = [jsonOverlaySettings valueForKey:@"dataMismatchTitle"]; 107 | if (dataMismatchTitle != nil) { 108 | sett.dataMismatchTitle = (NSString *)dataMismatchTitle; 109 | } 110 | } 111 | 112 | { 113 | id dataMismatchMessage = [jsonOverlaySettings valueForKey:@"dataMismatchMessage"]; 114 | if (dataMismatchMessage != nil) { 115 | sett.dataMismatchMessage = (NSString *)dataMismatchMessage; 116 | } 117 | } 118 | 119 | { 120 | id unsupportedDocumentTitle = [jsonOverlaySettings valueForKey:@"unsupportedDocumentTitle"]; 121 | if (unsupportedDocumentTitle != nil) { 122 | sett.unsupportedDocumentTitle = (NSString *)unsupportedDocumentTitle; 123 | } 124 | } 125 | 126 | { 127 | id unsupportedDocumentMessage = [jsonOverlaySettings valueForKey:@"unsupportedDocumentMessage"]; 128 | if (unsupportedDocumentMessage != nil) { 129 | sett.unsupportedDocumentMessage = (NSString *)unsupportedDocumentMessage; 130 | } 131 | } 132 | 133 | { 134 | id recognitionTimeoutTitle = [jsonOverlaySettings valueForKey:@"recognitionTimeoutTitle"]; 135 | if (recognitionTimeoutTitle != nil) { 136 | sett.recognitionTimeoutTitle = (NSString *)recognitionTimeoutTitle; 137 | } 138 | } 139 | 140 | { 141 | id recognitionTimeoutMessage = [jsonOverlaySettings valueForKey:@"recognitionTimeoutMessage"]; 142 | if (recognitionTimeoutMessage != nil) { 143 | sett.recognitionTimeoutMessage = (NSString *)recognitionTimeoutMessage; 144 | } 145 | } 146 | 147 | { 148 | id retryButtonText = [jsonOverlaySettings valueForKey:@"retryButtonText"]; 149 | if (retryButtonText != nil) { 150 | sett.retryButtonText = (NSString *)retryButtonText; 151 | } 152 | } 153 | 154 | { 155 | id errorDocumentTooCloseToEdge = [jsonOverlaySettings valueForKey:@"errorDocumentTooCloseToEdge"]; 156 | if (errorDocumentTooCloseToEdge != nil) { 157 | sett.errorDocumentTooCloseToEdge = (NSString *)errorDocumentTooCloseToEdge; 158 | } 159 | } 160 | 161 | { 162 | id scanBarcodeText = [jsonOverlaySettings valueForKey:@"scanBarcodeText"]; 163 | if (scanBarcodeText != nil) { 164 | sett.scanBarcodeText = (NSString *)scanBarcodeText; 165 | } 166 | } 167 | 168 | { 169 | id errorMandatoryFieldMissing = [jsonOverlaySettings valueForKey:@"errorDocumentNotFullyVisible"]; 170 | if (errorMandatoryFieldMissing != nil) { 171 | sett.errorMandatoryFieldMissing = (NSString *)errorMandatoryFieldMissing; 172 | } 173 | } 174 | 175 | { 176 | id showOnboardingInfo = [jsonOverlaySettings valueForKey:@"showOnboardingInfo"]; 177 | if (showOnboardingInfo != nil) { 178 | sett.showOnboardingInfo = [showOnboardingInfo boolValue]; 179 | } 180 | } 181 | 182 | { 183 | id showIntroductionDialog = [jsonOverlaySettings valueForKey:@"showIntroductionDialog"]; 184 | if (showIntroductionDialog != nil) { 185 | sett.showIntroductionDialog = [showIntroductionDialog boolValue]; 186 | } 187 | } 188 | 189 | { 190 | id onboardingButtonTooltipDelay = [jsonOverlaySettings valueForKey:@"onboardingButtonTooltipDelay"]; 191 | if (onboardingButtonTooltipDelay != nil) { 192 | sett.onboardingButtonTooltipDelay = [onboardingButtonTooltipDelay doubleValue] / 1000.0; 193 | } 194 | } 195 | 196 | { 197 | id showMandatoryFieldsMissing = [jsonOverlaySettings valueForKey: @"showMandatoryFieldsMissing"]; 198 | if (showMandatoryFieldsMissing != nil) { 199 | sett.defineSpecificMissingMandatoryFields = [showMandatoryFieldsMissing boolValue]; 200 | } 201 | } 202 | 203 | { 204 | id showTorchButton = [jsonOverlaySettings valueForKey: @"showTorchButton"]; 205 | if (showTorchButton != nil) { 206 | sett.displayTorchButton = [showTorchButton boolValue]; 207 | } 208 | } 209 | 210 | { 211 | id showCancelButton = [jsonOverlaySettings valueForKey: @"showCancelButton"]; 212 | if (showCancelButton != nil) { 213 | sett.displayCancelButton = [showCancelButton boolValue]; 214 | } 215 | } 216 | 217 | { 218 | id iOSCameraResolutionPreset = [jsonOverlaySettings valueForKey: @"iosCameraResolutionPreset"]; 219 | if (iOSCameraResolutionPreset != nil) { 220 | sett.cameraSettings.cameraPreset = [iOSCameraResolutionPreset integerValue]; 221 | } 222 | } 223 | 224 | { 225 | id errorBlurDetected = [jsonOverlaySettings valueForKey:@"errorBlurDetected"]; 226 | if (errorBlurDetected != nil) { 227 | sett.blurDetectedMessage = (NSString *)errorBlurDetected; 228 | } 229 | } 230 | 231 | { 232 | id errorGlareDetected = [jsonOverlaySettings valueForKey:@"errorGlareDetected"]; 233 | if (errorGlareDetected != nil) { 234 | sett.glareDetectedMessage = (NSString *)errorGlareDetected; 235 | } 236 | } 237 | { 238 | id topPageInstructions = [jsonOverlaySettings valueForKey:@"topPageInstructions"]; 239 | if (topPageInstructions != nil) { 240 | sett.scanTopPageInstructions = (NSString *)topPageInstructions; 241 | } 242 | } 243 | { 244 | id leftPageInstructions = [jsonOverlaySettings valueForKey:@"leftPageInstructions"]; 245 | if (leftPageInstructions != nil) { 246 | sett.scanLeftPageInstructions = (NSString *)leftPageInstructions; 247 | } 248 | } 249 | { 250 | id rightPageInstructions = [jsonOverlaySettings valueForKey:@"rightPageInstructions"]; 251 | if (rightPageInstructions != nil) { 252 | sett.scanRightPageInstructions = (NSString *)rightPageInstructions; 253 | } 254 | } 255 | { 256 | id turnTopPageInstructions = [jsonOverlaySettings valueForKey:@"turnTopPageInstructions"]; 257 | if (turnTopPageInstructions != nil) { 258 | sett.turnTopPageInstructions = (NSString *)turnTopPageInstructions; 259 | } 260 | } 261 | { 262 | id turnLeftPageInstructions = [jsonOverlaySettings valueForKey:@"turnLeftPageInstructions"]; 263 | if (turnLeftPageInstructions != nil) { 264 | sett.turnLeftPageInstructions = (NSString *)turnLeftPageInstructions; 265 | } 266 | } 267 | { 268 | id turnRightPageInstructions = [jsonOverlaySettings valueForKey:@"turnRightPageInstructions"]; 269 | if (turnRightPageInstructions != nil) { 270 | sett.turnRightPageInstructions = (NSString *)turnRightPageInstructions; 271 | } 272 | } 273 | { 274 | id errorScanningWrongPageTop = [jsonOverlaySettings valueForKey:@"errorScanningWrongPageTop"]; 275 | if (errorScanningWrongPageTop != nil) { 276 | sett.scanningWrongSidePassportTopMessage = (NSString *)errorScanningWrongPageTop; 277 | } 278 | } 279 | { 280 | id errorScanningWrongPageLeft = [jsonOverlaySettings valueForKey:@"errorScanningWrongPageLeft"]; 281 | if (errorScanningWrongPageLeft != nil) { 282 | sett.scanningWrongSidePassportLeftMessage = (NSString *)errorScanningWrongPageLeft; 283 | } 284 | } 285 | { 286 | id errorScanningWrongPageRight = [jsonOverlaySettings valueForKey:@"errorScanningWrongPageRight"]; 287 | if (errorScanningWrongPageRight != nil) { 288 | sett.scanningWrongSidePassportRightMessage = (NSString *)errorScanningWrongPageRight; 289 | } 290 | } 291 | 292 | return [[MBBlinkIdOverlayViewController alloc] initWithSettings:sett recognizerCollection:recognizerCollection delegate:self]; 293 | } 294 | 295 | 296 | - (void)blinkIdOverlayViewControllerDidFinishScanning:(nonnull MBBlinkIdOverlayViewController *)blinkIdOverlayViewController state:(MBRecognizerResultState)state { 297 | [self.delegate overlayViewControllerDidFinishScanning:blinkIdOverlayViewController state:state]; 298 | } 299 | 300 | - (void)blinkIdOverlayViewControllerDidTapClose:(nonnull MBBlinkIdOverlayViewController *)blinkIdOverlayViewController { 301 | [self.delegate overlayDidTapClose:blinkIdOverlayViewController]; 302 | } 303 | 304 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/Serialization/MBDocumentOverlaySettingsSerialization.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBDocumentOverlaySettingsSerialization.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBOverlayVCCreator.h" 9 | #import 10 | 11 | @interface MBDocumentOverlaySettingsSerialization : NSObject 12 | 13 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/Serialization/MBDocumentOverlaySettingsSerialization.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBDocumentOverlaySettingsSerialization.m 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBDocumentOverlaySettingsSerialization.h" 9 | #import "MBOverlaySerializationUtils.h" 10 | 11 | @interface MBDocumentOverlaySettingsSerialization () 12 | 13 | @property (nonatomic, weak) id delegate; 14 | 15 | @end 16 | 17 | @implementation MBDocumentOverlaySettingsSerialization 18 | 19 | @synthesize jsonName = _jsonName; 20 | 21 | -(instancetype) init { 22 | self = [super init]; 23 | if (self) { 24 | _jsonName = @"DocumentOverlaySettings"; 25 | } 26 | return self; 27 | } 28 | 29 | -(MBOverlayViewController *) createOverlayViewController:(NSDictionary *)jsonOverlaySettings recognizerCollection:(MBRecognizerCollection*)recognizerCollection delegate:(id) delegate { 30 | // no settings deserialized at the moment 31 | MBDocumentOverlaySettings *sett = [[MBDocumentOverlaySettings alloc] init]; 32 | self.delegate = delegate; 33 | [MBOverlaySerializationUtils extractCommonOverlaySettings:jsonOverlaySettings overlaySettings:sett]; 34 | return [[MBDocumentOverlayViewController alloc] initWithSettings:sett recognizerCollection:recognizerCollection delegate:self]; 35 | } 36 | 37 | - (void)documentOverlayViewControllerDidFinishScanning:(nonnull MBDocumentOverlayViewController *)documentOverlayViewController state:(MBRecognizerResultState)state { 38 | [self.delegate overlayViewControllerDidFinishScanning:documentOverlayViewController state:state]; 39 | } 40 | 41 | - (void)documentOverlayViewControllerDidTapClose:(nonnull MBDocumentOverlayViewController *)documentOverlayViewController { 42 | [self.delegate overlayDidTapClose:documentOverlayViewController]; 43 | } 44 | 45 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/Serialization/MBDocumentVerificationOverlaySettingsSerialization.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBDocumentVerificationOverlaySettingsSerialization.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBOverlayVCCreator.h" 9 | 10 | #import 11 | 12 | @interface MBDocumentVerificationOverlaySettingsSerialization : NSObject 13 | 14 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Overlays/Serialization/MBDocumentVerificationOverlaySettingsSerialization.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBDocumentVerificationOverlaySettingsSerialization.m 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 04/06/2018. 6 | // 7 | 8 | #import "MBDocumentVerificationOverlaySettingsSerialization.h" 9 | #import "MBOverlaySerializationUtils.h" 10 | 11 | @interface MBDocumentVerificationOverlaySettingsSerialization () 12 | 13 | @property (nonatomic, weak) id delegate; 14 | 15 | @end 16 | 17 | @implementation MBDocumentVerificationOverlaySettingsSerialization 18 | 19 | @synthesize jsonName = _jsonName; 20 | 21 | -(instancetype) init { 22 | self = [super init]; 23 | if (self) { 24 | _jsonName = @"DocumentVerificationOverlaySettings"; 25 | } 26 | return self; 27 | } 28 | 29 | -(MBOverlayViewController *) createOverlayViewController:(NSDictionary *)jsonOverlaySettings recognizerCollection:(MBRecognizerCollection*)recognizerCollection delegate:(id) delegate { 30 | // no settings deserialized at the moment 31 | MBLegacyDocumentVerificationOverlaySettings*sett = [[MBLegacyDocumentVerificationOverlaySettings alloc] init]; 32 | self.delegate = delegate; 33 | [MBOverlaySerializationUtils extractCommonOverlaySettings:jsonOverlaySettings overlaySettings:sett]; 34 | 35 | { 36 | id firstSideSplashMessage = [jsonOverlaySettings valueForKey:@"firstSideSplashMessage"]; 37 | if (firstSideSplashMessage != nil) { 38 | sett.firstSideSplashMessage = (NSString *)firstSideSplashMessage; 39 | } 40 | } 41 | 42 | { 43 | id secondSideSplashMessage = [jsonOverlaySettings valueForKey:@"secondSideSplashMessage"]; 44 | if (secondSideSplashMessage != nil) { 45 | sett.secondSideSplashMessage = (NSString *)secondSideSplashMessage; 46 | } 47 | } 48 | 49 | { 50 | id scanningDoneSplashMessage = [jsonOverlaySettings valueForKey:@"scanningDoneSplashMessage"]; 51 | if (scanningDoneSplashMessage != nil) { 52 | sett.scanningDoneSplashMessage = (NSString *)scanningDoneSplashMessage; 53 | } 54 | } 55 | 56 | { 57 | id firstSideInstructions = [jsonOverlaySettings valueForKey:@"firstSideInstructions"]; 58 | if (firstSideInstructions != nil) { 59 | sett.firstSideInstructions = (NSString *)firstSideInstructions; 60 | } 61 | } 62 | 63 | { 64 | id secondSideInstructions = [jsonOverlaySettings valueForKey:@"secondSideInstructions"]; 65 | if (secondSideInstructions != nil) { 66 | sett.secondSideInstructions = (NSString *)secondSideInstructions; 67 | } 68 | } 69 | 70 | { 71 | id glareMessage = [jsonOverlaySettings valueForKey:@"glareMessage"]; 72 | if (glareMessage != nil) { 73 | sett.glareMessage = (NSString *)glareMessage; 74 | } 75 | } 76 | 77 | return [[MBLegacyDocumentVerificationOverlayViewController alloc] initWithSettings:sett recognizerCollection:recognizerCollection delegate:self]; 78 | } 79 | 80 | 81 | - (void)legacyDocumentVerificationOverlayViewControllerDidFinishScanning:(nonnull MBLegacyDocumentVerificationOverlayViewController *)documentVerificationOverlayViewController state:(MBRecognizerResultState)state { 82 | [self.delegate overlayViewControllerDidFinishScanning:documentVerificationOverlayViewController state:state]; 83 | } 84 | 85 | - (void)legacyDocumentVerificationOverlayViewControllerDidTapClose:(nonnull MBLegacyDocumentVerificationOverlayViewController *)documentVerificationOverlayViewController { 86 | [self.delegate overlayDidTapClose:documentVerificationOverlayViewController]; 87 | } 88 | 89 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/MBRecognizerSerializers.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | 3 | #import 4 | 5 | #import 6 | 7 | @interface MBRecognizerSerializers : NSObject 8 | 9 | +(instancetype) sharedInstance; 10 | 11 | -(MBRecognizerCollection *) deserializeRecognizerCollection:(NSDictionary *)jsonRecognizerCollection; 12 | -(id) recognizerCreatorForJson:(NSDictionary *)recognizerJson; 13 | 14 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/MBRecognizerSerializers.m: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerSerializers.h" 2 | 3 | #import "MBRecognizerWrapper.h" 4 | #import "MBSuccessFrameGrabberRecognizerWrapper.h" 5 | #import "MBBlinkIdMultiSideRecognizerWrapper.h" 6 | #import "MBBlinkIdSingleSideRecognizerWrapper.h" 7 | #import "MBDocumentFaceRecognizerWrapper.h" 8 | #import "MBIdBarcodeRecognizerWrapper.h" 9 | #import "MBMrtdCombinedRecognizerWrapper.h" 10 | #import "MBMrtdRecognizerWrapper.h" 11 | #import "MBPassportRecognizerWrapper.h" 12 | #import "MBVisaRecognizerWrapper.h" 13 | #import "MBUsdlRecognizerWrapper.h" 14 | #import "MBUsdlCombinedRecognizerWrapper.h" 15 | 16 | 17 | @interface MBRecognizerSerializers () 18 | 19 | @property (nonatomic, strong) NSDictionary> *recognizerSerializers; 20 | 21 | @end 22 | 23 | @implementation MBRecognizerSerializers 24 | 25 | - (void)registerCreator:(id)recognizerCreator { 26 | [self.recognizerSerializers setValue:recognizerCreator forKey:recognizerCreator.jsonName]; 27 | } 28 | 29 | - (instancetype)init { 30 | self = [super init]; 31 | if (self) { 32 | _recognizerSerializers = [[NSMutableDictionary alloc] init]; 33 | [self registerCreator:[[MBSuccessFrameGrabberRecognizerCreator alloc] init]]; 34 | [self registerCreator:[[MBBlinkIdMultiSideRecognizerCreator alloc] init]]; 35 | [self registerCreator:[[MBBlinkIdSingleSideRecognizerCreator alloc] init]]; 36 | [self registerCreator:[[MBDocumentFaceRecognizerCreator alloc] init]]; 37 | [self registerCreator:[[MBIdBarcodeRecognizerCreator alloc] init]]; 38 | [self registerCreator:[[MBMrtdCombinedRecognizerCreator alloc] init]]; 39 | [self registerCreator:[[MBMrtdRecognizerCreator alloc] init]]; 40 | [self registerCreator:[[MBPassportRecognizerCreator alloc] init]]; 41 | [self registerCreator:[[MBVisaRecognizerCreator alloc] init]]; 42 | [self registerCreator:[[MBUsdlRecognizerCreator alloc] init]]; 43 | [self registerCreator:[[MBUsdlCombinedRecognizerCreator alloc] init]]; 44 | 45 | } 46 | return self; 47 | } 48 | 49 | + (instancetype)sharedInstance { 50 | static MBRecognizerSerializers *sharedInstance = nil; 51 | static dispatch_once_t onceToken; 52 | dispatch_once(&onceToken, ^{ 53 | sharedInstance = [[self alloc] init]; 54 | 55 | }); 56 | return sharedInstance; 57 | } 58 | 59 | -(id) recognizerCreatorForJson:(NSDictionary *)recognizerJson { 60 | NSString* recognizerType = [recognizerJson objectForKey:@"recognizerType"]; 61 | return [self.recognizerSerializers objectForKey:recognizerType]; 62 | } 63 | 64 | -(MBRecognizerCollection *) deserializeRecognizerCollection:(NSDictionary *)jsonRecognizerCollection { 65 | NSArray *recognizerArray = [jsonRecognizerCollection valueForKey:@"recognizerArray"]; 66 | NSUInteger numRecognizers = recognizerArray.count; 67 | 68 | NSMutableArray *recognizers = [[NSMutableArray alloc] initWithCapacity:numRecognizers]; 69 | for (NSUInteger i = 0; i < numRecognizers; ++i) { 70 | NSDictionary* recognizerJson = [recognizerArray objectAtIndex:i]; 71 | [recognizers addObject:[[self recognizerCreatorForJson:recognizerJson] createRecognizer:recognizerArray[i]]]; 72 | } 73 | 74 | MBRecognizerCollection* recognizerCollection = [[MBRecognizerCollection alloc] initWithRecognizers:recognizers]; 75 | { 76 | id allowMultipleResults = [jsonRecognizerCollection objectForKey:@"allowMultipleResults"]; 77 | if (allowMultipleResults != nil) { 78 | recognizerCollection.allowMultipleResults = [(NSNumber*)allowMultipleResults boolValue]; 79 | } 80 | } 81 | { 82 | id milisecondsBeforeTimeout = [jsonRecognizerCollection objectForKey:@"milisecondsBeforeTimeout"]; 83 | if (milisecondsBeforeTimeout != nil) { 84 | recognizerCollection.partialRecognitionTimeout = (NSTimeInterval)[(NSNumber*)milisecondsBeforeTimeout integerValue] / 1000.0; 85 | } 86 | } 87 | return recognizerCollection; 88 | } 89 | 90 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/MBRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBRecognizerWrapper.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 01/06/2018. 6 | // 7 | 8 | #pragma once 9 | 10 | #import 11 | 12 | /** Object that knows how to create recognizer from JSON */ 13 | @protocol MBRecognizerCreator 14 | @required 15 | 16 | - (MBRecognizer * _Nullable)createRecognizer:(NSDictionary * _Nullable) jsonRecognizer; 17 | 18 | @property (nonatomic, nonnull, readonly) NSString* jsonName; 19 | 20 | @end 21 | 22 | /** Category on MBRecognizer that adds support writing its result to JSON */ 23 | 24 | @interface MBRecognizer (JsonSerialization) 25 | 26 | - (NSDictionary * _Nullable)serializeResult; 27 | 28 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/MBRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBRecognizer+MBRecognizerWrapper_m.h 3 | // BlinkIdDevDemo 4 | // 5 | // Created by DoDo on 01/06/2018. 6 | // 7 | 8 | #import "MBRecognizerWrapper.h" 9 | #import 10 | 11 | @implementation MBRecognizer (JsonSerialization) 12 | 13 | -(NSDictionary *) serializeResult { 14 | NSMutableDictionary* result = [[NSMutableDictionary alloc] init]; 15 | 16 | [result setObject:[NSNumber numberWithUnsignedInteger:self.baseResult.resultState] forKey:@"resultState"]; 17 | return result; 18 | } 19 | 20 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBBlinkIdMultiSideRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBBlinkIdMultiSideRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBBlinkIdSingleSideRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBBlinkIdSingleSideRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBDocumentFaceRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBDocumentFaceRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBDocumentFaceRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBDocumentFaceRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | #import "MBCommonSerializationUtils.h" 5 | 6 | @implementation MBDocumentFaceRecognizerCreator 7 | 8 | @synthesize jsonName = _jsonName; 9 | 10 | -(instancetype) init { 11 | self = [super init]; 12 | if (self) { 13 | _jsonName = @"DocumentFaceRecognizer"; 14 | } 15 | return self; 16 | } 17 | 18 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 19 | MBDocumentFaceRecognizer *recognizer = [[MBDocumentFaceRecognizer alloc] init]; 20 | { 21 | id detectorType = [jsonRecognizer valueForKey:@"detectorType"]; 22 | if (detectorType != nil) { 23 | recognizer.detectorType = (MBDocumentFaceDetectorType)[(NSNumber *)detectorType unsignedIntegerValue]; 24 | } 25 | } 26 | { 27 | id faceImageDpi = [jsonRecognizer valueForKey:@"faceImageDpi"]; 28 | if (faceImageDpi != nil) { 29 | recognizer.faceImageDpi = [(NSNumber *)faceImageDpi integerValue]; 30 | } 31 | } 32 | { 33 | id fullDocumentImageDpi = [jsonRecognizer valueForKey:@"fullDocumentImageDpi"]; 34 | if (fullDocumentImageDpi != nil) { 35 | recognizer.fullDocumentImageDpi = [(NSNumber *)fullDocumentImageDpi integerValue]; 36 | } 37 | } 38 | { 39 | id fullDocumentImageExtensionFactors = [jsonRecognizer valueForKey:@"fullDocumentImageExtensionFactors"]; 40 | if (fullDocumentImageExtensionFactors != nil) { 41 | recognizer.fullDocumentImageExtensionFactors = [MBCommonSerializationUtils deserializeMBImageExtensionFactors:(NSDictionary*)fullDocumentImageExtensionFactors]; 42 | } 43 | } 44 | { 45 | id numStableDetectionsThreshold = [jsonRecognizer valueForKey:@"numStableDetectionsThreshold"]; 46 | if (numStableDetectionsThreshold != nil) { 47 | recognizer.numStableDetectionsThreshold = [(NSNumber *)numStableDetectionsThreshold integerValue]; 48 | } 49 | } 50 | { 51 | id returnFaceImage = [jsonRecognizer valueForKey:@"returnFaceImage"]; 52 | if (returnFaceImage != nil) { 53 | recognizer.returnFaceImage = [(NSNumber *)returnFaceImage boolValue]; 54 | } 55 | } 56 | { 57 | id returnFullDocumentImage = [jsonRecognizer valueForKey:@"returnFullDocumentImage"]; 58 | if (returnFullDocumentImage != nil) { 59 | recognizer.returnFullDocumentImage = [(NSNumber *)returnFullDocumentImage boolValue]; 60 | } 61 | } 62 | 63 | return recognizer; 64 | } 65 | 66 | @end 67 | 68 | @interface MBDocumentFaceRecognizer (JsonSerialization) 69 | @end 70 | 71 | @implementation MBDocumentFaceRecognizer (JsonSerialization) 72 | 73 | -(NSDictionary *) serializeResult { 74 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 75 | [jsonResult setValue:[MBSerializationUtils serializeMBQuadrangle:self.result.documentLocation] forKey:@"documentLocation"]; 76 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.faceImage] forKey:@"faceImage"]; 77 | [jsonResult setValue:[MBSerializationUtils serializeMBQuadrangle:self.result.faceLocation] forKey:@"faceLocation"]; 78 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentImage] forKey:@"fullDocumentImage"]; 79 | 80 | return jsonResult; 81 | } 82 | 83 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBIdBarcodeRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBIdBarcodeRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBIdBarcodeRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBIdBarcodeRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | #import "MBCommonSerializationUtils.h" 5 | 6 | @implementation MBIdBarcodeRecognizerCreator 7 | 8 | @synthesize jsonName = _jsonName; 9 | 10 | -(instancetype) init { 11 | self = [super init]; 12 | if (self) { 13 | _jsonName = @"IdBarcodeRecognizer"; 14 | } 15 | return self; 16 | } 17 | 18 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 19 | MBIdBarcodeRecognizer *recognizer = [[MBIdBarcodeRecognizer alloc] init]; 20 | 21 | return recognizer; 22 | } 23 | 24 | @end 25 | 26 | @interface MBIdBarcodeRecognizer (JsonSerialization) 27 | @end 28 | 29 | @implementation MBIdBarcodeRecognizer (JsonSerialization) 30 | 31 | -(NSDictionary *) serializeResult { 32 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 33 | [jsonResult setValue:self.result.additionalNameInformation forKey:@"additionalNameInformation"]; 34 | [jsonResult setValue:self.result.address forKey:@"address"]; 35 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.age] forKey:@"age"]; 36 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.barcodeType] forKey:@"barcodeType"]; 37 | [jsonResult setValue:self.result.city forKey:@"city"]; 38 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfBirth] forKey:@"dateOfBirth"]; 39 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfExpiry] forKey:@"dateOfExpiry"]; 40 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfIssue] forKey:@"dateOfIssue"]; 41 | [jsonResult setValue:self.result.documentAdditionalNumber forKey:@"documentAdditionalNumber"]; 42 | [jsonResult setValue:self.result.documentNumber forKey:@"documentNumber"]; 43 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.documentType] forKey:@"documentType"]; 44 | [jsonResult setValue:self.result.employer forKey:@"employer"]; 45 | [jsonResult setValue:self.result.endorsements forKey:@"endorsements"]; 46 | [jsonResult setValue:[NSNumber numberWithBool:self.result.expired] forKey:@"expired"]; 47 | [jsonResult setValue:[MBBlinkIDSerializationUtils serializeBarcodeElements:self.result.extendedElements] forKey:@"extendedElements"]; 48 | [jsonResult setValue:self.result.firstName forKey:@"firstName"]; 49 | [jsonResult setValue:self.result.fullName forKey:@"fullName"]; 50 | [jsonResult setValue:self.result.issuingAuthority forKey:@"issuingAuthority"]; 51 | [jsonResult setValue:self.result.jurisdiction forKey:@"jurisdiction"]; 52 | [jsonResult setValue:self.result.lastName forKey:@"lastName"]; 53 | [jsonResult setValue:self.result.maritalStatus forKey:@"maritalStatus"]; 54 | [jsonResult setValue:self.result.middleName forKey:@"middleName"]; 55 | [jsonResult setValue:self.result.nationality forKey:@"nationality"]; 56 | [jsonResult setValue:self.result.personalIdNumber forKey:@"personalIdNumber"]; 57 | [jsonResult setValue:self.result.placeOfBirth forKey:@"placeOfBirth"]; 58 | [jsonResult setValue:self.result.postalCode forKey:@"postalCode"]; 59 | [jsonResult setValue:self.result.profession forKey:@"profession"]; 60 | [jsonResult setValue:self.result.race forKey:@"race"]; 61 | [jsonResult setValue:[self.result.rawData base64EncodedStringWithOptions:0] forKey:@"rawData"]; 62 | [jsonResult setValue:self.result.religion forKey:@"religion"]; 63 | [jsonResult setValue:self.result.residentialStatus forKey:@"residentialStatus"]; 64 | [jsonResult setValue:self.result.restrictions forKey:@"restrictions"]; 65 | [jsonResult setValue:self.result.sex forKey:@"sex"]; 66 | [jsonResult setValue:self.result.street forKey:@"street"]; 67 | [jsonResult setValue:self.result.stringData forKey:@"stringData"]; 68 | [jsonResult setValue:[NSNumber numberWithBool:self.result.uncertain] forKey:@"uncertain"]; 69 | [jsonResult setValue:self.result.vehicleClass forKey:@"vehicleClass"]; 70 | 71 | return jsonResult; 72 | } 73 | 74 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBMrtdCombinedRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBMrtdCombinedRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBMrtdCombinedRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBMrtdCombinedRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | #import "MBCommonSerializationUtils.h" 5 | 6 | @implementation MBMrtdCombinedRecognizerCreator 7 | 8 | @synthesize jsonName = _jsonName; 9 | 10 | -(instancetype) init { 11 | self = [super init]; 12 | if (self) { 13 | _jsonName = @"MrtdCombinedRecognizer"; 14 | } 15 | return self; 16 | } 17 | 18 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 19 | MBMrtdCombinedRecognizer *recognizer = [[MBMrtdCombinedRecognizer alloc] init]; 20 | { 21 | id allowSpecialCharacters = [jsonRecognizer valueForKey:@"allowSpecialCharacters"]; 22 | if (allowSpecialCharacters != nil) { 23 | recognizer.allowSpecialCharacters = [(NSNumber *)allowSpecialCharacters boolValue]; 24 | } 25 | } 26 | { 27 | id allowUnparsedResults = [jsonRecognizer valueForKey:@"allowUnparsedResults"]; 28 | if (allowUnparsedResults != nil) { 29 | recognizer.allowUnparsedResults = [(NSNumber *)allowUnparsedResults boolValue]; 30 | } 31 | } 32 | { 33 | id allowUnverifiedResults = [jsonRecognizer valueForKey:@"allowUnverifiedResults"]; 34 | if (allowUnverifiedResults != nil) { 35 | recognizer.allowUnverifiedResults = [(NSNumber *)allowUnverifiedResults boolValue]; 36 | } 37 | } 38 | { 39 | id detectorType = [jsonRecognizer valueForKey:@"detectorType"]; 40 | if (detectorType != nil) { 41 | recognizer.detectorType = (MBDocumentFaceDetectorType)[(NSNumber *)detectorType unsignedIntegerValue]; 42 | } 43 | } 44 | { 45 | id faceImageDpi = [jsonRecognizer valueForKey:@"faceImageDpi"]; 46 | if (faceImageDpi != nil) { 47 | recognizer.faceImageDpi = [(NSNumber *)faceImageDpi integerValue]; 48 | } 49 | } 50 | { 51 | id fullDocumentImageDpi = [jsonRecognizer valueForKey:@"fullDocumentImageDpi"]; 52 | if (fullDocumentImageDpi != nil) { 53 | recognizer.fullDocumentImageDpi = [(NSNumber *)fullDocumentImageDpi integerValue]; 54 | } 55 | } 56 | { 57 | id fullDocumentImageExtensionFactors = [jsonRecognizer valueForKey:@"fullDocumentImageExtensionFactors"]; 58 | if (fullDocumentImageExtensionFactors != nil) { 59 | recognizer.fullDocumentImageExtensionFactors = [MBCommonSerializationUtils deserializeMBImageExtensionFactors:(NSDictionary*)fullDocumentImageExtensionFactors]; 60 | } 61 | } 62 | { 63 | id numStableDetectionsThreshold = [jsonRecognizer valueForKey:@"numStableDetectionsThreshold"]; 64 | if (numStableDetectionsThreshold != nil) { 65 | recognizer.numStableDetectionsThreshold = [(NSNumber *)numStableDetectionsThreshold integerValue]; 66 | } 67 | } 68 | { 69 | id returnFaceImage = [jsonRecognizer valueForKey:@"returnFaceImage"]; 70 | if (returnFaceImage != nil) { 71 | recognizer.returnFaceImage = [(NSNumber *)returnFaceImage boolValue]; 72 | } 73 | } 74 | { 75 | id returnFullDocumentImage = [jsonRecognizer valueForKey:@"returnFullDocumentImage"]; 76 | if (returnFullDocumentImage != nil) { 77 | recognizer.returnFullDocumentImage = [(NSNumber *)returnFullDocumentImage boolValue]; 78 | } 79 | } 80 | 81 | return recognizer; 82 | } 83 | 84 | @end 85 | 86 | @interface MBMrtdCombinedRecognizer (JsonSerialization) 87 | @end 88 | 89 | @implementation MBMrtdCombinedRecognizer (JsonSerialization) 90 | 91 | -(NSDictionary *) serializeResult { 92 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 93 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.documentDataMatch] forKey:@"documentDataMatch"]; 94 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.faceImage] forKey:@"faceImage"]; 95 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentBackImage] forKey:@"fullDocumentBackImage"]; 96 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentFrontImage] forKey:@"fullDocumentFrontImage"]; 97 | [jsonResult setValue:[MBBlinkIDSerializationUtils serializeMrzResult:self.result.mrzResult] forKey:@"mrzResult"]; 98 | [jsonResult setValue:[NSNumber numberWithBool:self.result.scanningFirstSideDone] forKey:@"scanningFirstSideDone"]; 99 | 100 | return jsonResult; 101 | } 102 | 103 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBMrtdRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBMrtdRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBMrtdRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBMrtdRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | #import "MBCommonSerializationUtils.h" 5 | 6 | @implementation MBMrtdRecognizerCreator 7 | 8 | @synthesize jsonName = _jsonName; 9 | 10 | -(instancetype) init { 11 | self = [super init]; 12 | if (self) { 13 | _jsonName = @"MrtdRecognizer"; 14 | } 15 | return self; 16 | } 17 | 18 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 19 | MBMrtdRecognizer *recognizer = [[MBMrtdRecognizer alloc] init]; 20 | { 21 | id allowSpecialCharacters = [jsonRecognizer valueForKey:@"allowSpecialCharacters"]; 22 | if (allowSpecialCharacters != nil) { 23 | recognizer.allowSpecialCharacters = [(NSNumber *)allowSpecialCharacters boolValue]; 24 | } 25 | } 26 | { 27 | id allowUnparsedResults = [jsonRecognizer valueForKey:@"allowUnparsedResults"]; 28 | if (allowUnparsedResults != nil) { 29 | recognizer.allowUnparsedResults = [(NSNumber *)allowUnparsedResults boolValue]; 30 | } 31 | } 32 | { 33 | id allowUnverifiedResults = [jsonRecognizer valueForKey:@"allowUnverifiedResults"]; 34 | if (allowUnverifiedResults != nil) { 35 | recognizer.allowUnverifiedResults = [(NSNumber *)allowUnverifiedResults boolValue]; 36 | } 37 | } 38 | { 39 | id detectGlare = [jsonRecognizer valueForKey:@"detectGlare"]; 40 | if (detectGlare != nil) { 41 | recognizer.detectGlare = [(NSNumber *)detectGlare boolValue]; 42 | } 43 | } 44 | { 45 | id fullDocumentImageDpi = [jsonRecognizer valueForKey:@"fullDocumentImageDpi"]; 46 | if (fullDocumentImageDpi != nil) { 47 | recognizer.fullDocumentImageDpi = [(NSNumber *)fullDocumentImageDpi integerValue]; 48 | } 49 | } 50 | { 51 | id fullDocumentImageExtensionFactors = [jsonRecognizer valueForKey:@"fullDocumentImageExtensionFactors"]; 52 | if (fullDocumentImageExtensionFactors != nil) { 53 | recognizer.fullDocumentImageExtensionFactors = [MBCommonSerializationUtils deserializeMBImageExtensionFactors:(NSDictionary*)fullDocumentImageExtensionFactors]; 54 | } 55 | } 56 | { 57 | id returnFullDocumentImage = [jsonRecognizer valueForKey:@"returnFullDocumentImage"]; 58 | if (returnFullDocumentImage != nil) { 59 | recognizer.returnFullDocumentImage = [(NSNumber *)returnFullDocumentImage boolValue]; 60 | } 61 | } 62 | 63 | return recognizer; 64 | } 65 | 66 | @end 67 | 68 | @interface MBMrtdRecognizer (JsonSerialization) 69 | @end 70 | 71 | @implementation MBMrtdRecognizer (JsonSerialization) 72 | 73 | -(NSDictionary *) serializeResult { 74 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 75 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentImage] forKey:@"fullDocumentImage"]; 76 | [jsonResult setValue:[MBBlinkIDSerializationUtils serializeMrzResult:self.result.mrzResult] forKey:@"mrzResult"]; 77 | 78 | return jsonResult; 79 | } 80 | 81 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBPassportRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBPassportRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBPassportRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBPassportRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | #import "MBCommonSerializationUtils.h" 5 | 6 | @implementation MBPassportRecognizerCreator 7 | 8 | @synthesize jsonName = _jsonName; 9 | 10 | -(instancetype) init { 11 | self = [super init]; 12 | if (self) { 13 | _jsonName = @"PassportRecognizer"; 14 | } 15 | return self; 16 | } 17 | 18 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 19 | MBPassportRecognizer *recognizer = [[MBPassportRecognizer alloc] init]; 20 | { 21 | id anonymizeNetherlandsMrz = [jsonRecognizer valueForKey:@"anonymizeNetherlandsMrz"]; 22 | if (anonymizeNetherlandsMrz != nil) { 23 | recognizer.anonymizeNetherlandsMrz = [(NSNumber *)anonymizeNetherlandsMrz boolValue]; 24 | } 25 | } 26 | { 27 | id detectGlare = [jsonRecognizer valueForKey:@"detectGlare"]; 28 | if (detectGlare != nil) { 29 | recognizer.detectGlare = [(NSNumber *)detectGlare boolValue]; 30 | } 31 | } 32 | { 33 | id faceImageDpi = [jsonRecognizer valueForKey:@"faceImageDpi"]; 34 | if (faceImageDpi != nil) { 35 | recognizer.faceImageDpi = [(NSNumber *)faceImageDpi integerValue]; 36 | } 37 | } 38 | { 39 | id fullDocumentImageDpi = [jsonRecognizer valueForKey:@"fullDocumentImageDpi"]; 40 | if (fullDocumentImageDpi != nil) { 41 | recognizer.fullDocumentImageDpi = [(NSNumber *)fullDocumentImageDpi integerValue]; 42 | } 43 | } 44 | { 45 | id fullDocumentImageExtensionFactors = [jsonRecognizer valueForKey:@"fullDocumentImageExtensionFactors"]; 46 | if (fullDocumentImageExtensionFactors != nil) { 47 | recognizer.fullDocumentImageExtensionFactors = [MBCommonSerializationUtils deserializeMBImageExtensionFactors:(NSDictionary*)fullDocumentImageExtensionFactors]; 48 | } 49 | } 50 | { 51 | id returnFaceImage = [jsonRecognizer valueForKey:@"returnFaceImage"]; 52 | if (returnFaceImage != nil) { 53 | recognizer.returnFaceImage = [(NSNumber *)returnFaceImage boolValue]; 54 | } 55 | } 56 | { 57 | id returnFullDocumentImage = [jsonRecognizer valueForKey:@"returnFullDocumentImage"]; 58 | if (returnFullDocumentImage != nil) { 59 | recognizer.returnFullDocumentImage = [(NSNumber *)returnFullDocumentImage boolValue]; 60 | } 61 | } 62 | 63 | return recognizer; 64 | } 65 | 66 | @end 67 | 68 | @interface MBPassportRecognizer (JsonSerialization) 69 | @end 70 | 71 | @implementation MBPassportRecognizer (JsonSerialization) 72 | 73 | -(NSDictionary *) serializeResult { 74 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 75 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.faceImage] forKey:@"faceImage"]; 76 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentImage] forKey:@"fullDocumentImage"]; 77 | [jsonResult setValue:[MBBlinkIDSerializationUtils serializeMrzResult:self.result.mrzResult] forKey:@"mrzResult"]; 78 | 79 | return jsonResult; 80 | } 81 | 82 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBSuccessFrameGrabberRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBSuccessFrameGrabberRecognizerWrapper.h 3 | // MicroblinkModule 4 | // 5 | // Created by DoDo on 15/06/2018. 6 | // Copyright © 2018 Jura Skrlec. All rights reserved. 7 | // 8 | 9 | #import "MBRecognizerWrapper.h" 10 | #import 11 | 12 | @interface MBSuccessFrameGrabberRecognizerCreator : NSObject 13 | 14 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBSuccessFrameGrabberRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBSuccessFrameGrabberRecognizerWrapper.m 3 | // MicroblinkModule 4 | // 5 | // Created by DoDo on 15/06/2018. 6 | // Copyright © 2018 Jura Skrlec. All rights reserved. 7 | // 8 | 9 | #import "MBSuccessFrameGrabberRecognizerWrapper.h" 10 | 11 | #import "MBRecognizerSerializers.h" 12 | #import "MBSerializationUtils.h" 13 | 14 | @implementation MBSuccessFrameGrabberRecognizerCreator 15 | 16 | @synthesize jsonName = _jsonName; 17 | 18 | -(instancetype) init { 19 | self = [super init]; 20 | if (self) { 21 | _jsonName = @"SuccessFrameGrabberRecognizer"; 22 | } 23 | return self; 24 | } 25 | 26 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 27 | // first obtain slave recognizer 28 | NSDictionary *jsonSlaveRecognizer = [jsonRecognizer valueForKey:@"slaveRecognizer"]; 29 | MBRecognizer *slaveRecognizer = [[[MBRecognizerSerializers sharedInstance] recognizerCreatorForJson:jsonSlaveRecognizer] createRecognizer:jsonSlaveRecognizer]; 30 | 31 | return [[MBSuccessFrameGrabberRecognizer alloc] initWithRecognizer:slaveRecognizer]; 32 | } 33 | 34 | @end 35 | 36 | @interface MBSuccessFrameGrabberRecognizer (JsonSerialization) 37 | @end 38 | 39 | @implementation MBSuccessFrameGrabberRecognizer (JsonSerialization) 40 | 41 | -(NSDictionary *) serializeResult { 42 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 43 | 44 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.successFrame] forKey:@"successFrame"]; 45 | [jsonResult setValue:[self.slaveRecognizer serializeResult] forKey:@"slaveRecognizerResult"]; 46 | 47 | return jsonResult; 48 | } 49 | 50 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBUsdlCombinedRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBUsdlCombinedRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBUsdlCombinedRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBUsdlCombinedRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | 5 | @implementation MBUsdlCombinedRecognizerCreator 6 | 7 | @synthesize jsonName = _jsonName; 8 | 9 | -(instancetype) init { 10 | self = [super init]; 11 | if (self) { 12 | _jsonName = @"UsdlCombinedRecognizer"; 13 | } 14 | return self; 15 | } 16 | 17 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 18 | MBUsdlCombinedRecognizer *recognizer = [[MBUsdlCombinedRecognizer alloc] init]; 19 | { 20 | id faceImageDpi = [jsonRecognizer valueForKey:@"faceImageDpi"]; 21 | if (faceImageDpi != nil) { 22 | recognizer.faceImageDpi = [(NSNumber *)faceImageDpi integerValue]; 23 | } 24 | } 25 | { 26 | id fullDocumentImageDpi = [jsonRecognizer valueForKey:@"fullDocumentImageDpi"]; 27 | if (fullDocumentImageDpi != nil) { 28 | recognizer.fullDocumentImageDpi = [(NSNumber *)fullDocumentImageDpi integerValue]; 29 | } 30 | } 31 | { 32 | id returnFaceImage = [jsonRecognizer valueForKey:@"returnFaceImage"]; 33 | if (returnFaceImage != nil) { 34 | recognizer.returnFaceImage = [(NSNumber *)returnFaceImage boolValue]; 35 | } 36 | } 37 | { 38 | id returnFullDocumentImage = [jsonRecognizer valueForKey:@"returnFullDocumentImage"]; 39 | if (returnFullDocumentImage != nil) { 40 | recognizer.returnFullDocumentImage = [(NSNumber *)returnFullDocumentImage boolValue]; 41 | } 42 | } 43 | { 44 | id numStableDetectionsThreshold = [jsonRecognizer valueForKey:@"numStableDetectionsThreshold"]; 45 | if (numStableDetectionsThreshold != nil) { 46 | recognizer.numStableDetectionsThreshold = [(NSNumber *)numStableDetectionsThreshold integerValue]; 47 | } 48 | } 49 | { 50 | id fullDocumentImageExtensionFactors = [jsonRecognizer valueForKey:@"fullDocumentImageExtensionFactors"]; 51 | if (fullDocumentImageExtensionFactors != nil) { 52 | recognizer.fullDocumentImageExtensionFactors = [MBBlinkIDSerializationUtils deserializeMBImageExtensionFactors:(NSDictionary*)fullDocumentImageExtensionFactors]; 53 | } 54 | } 55 | 56 | return recognizer; 57 | } 58 | 59 | @end 60 | 61 | @interface MBUsdlCombinedRecognizer (JsonSerialization) 62 | @end 63 | 64 | @implementation MBUsdlCombinedRecognizer (JsonSerialization) 65 | 66 | -(NSDictionary *) serializeResult { 67 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 68 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.documentDataMatch] forKey:@"documentDataMatch"]; 69 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.faceImage] forKey:@"faceImage"]; 70 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentImage] forKey:@"fullDocumentImage"]; 71 | [jsonResult setValue:[NSNumber numberWithBool:self.result.scanningFirstSideDone] forKey:@"scanningFirstSideDone"]; 72 | 73 | [jsonResult setValue:self.result.firstName forKey:@"firstName"]; 74 | [jsonResult setValue:self.result.middleName forKey:@"middleName"]; 75 | [jsonResult setValue:self.result.lastName forKey:@"lastName"]; 76 | [jsonResult setValue:self.result.fullName forKey:@"fullName"]; 77 | [jsonResult setValue:self.result.nameSuffix forKey:@"nameSuffix"]; 78 | [jsonResult setValue:self.result.address forKey:@"address"]; 79 | [jsonResult setValue:self.result.documentNumber forKey:@"documentNumber"]; 80 | [jsonResult setValue:self.result.sex forKey:@"sex"]; 81 | [jsonResult setValue:self.result.restrictions forKey:@"restrictions"]; 82 | [jsonResult setValue:self.result.endorsements forKey:@"endorsements"]; 83 | [jsonResult setValue:self.result.vehicleClass forKey:@"vehicleClass"]; 84 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfBirth] forKey:@"dateOfBirth"]; 85 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfIssue] forKey:@"dateOfIssue"]; 86 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfExpiry] forKey:@"dateOfExpiry"]; 87 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.age] forKey:@"age"]; 88 | 89 | [jsonResult setValue:[self.result optionalElements] forKey:@"optionalElements"]; 90 | [jsonResult setValue:[[self.result data] base64EncodedStringWithOptions:0] forKey:@"rawData"]; 91 | [jsonResult setValue:[[NSString alloc] initWithData:[self.result data] encoding:NSUTF8StringEncoding] forKey:@"rawStringData"]; 92 | [jsonResult setValue:[NSNumber numberWithBool:[self.result isUncertain]] forKey:@"uncertain"]; 93 | [jsonResult setValue:[self serializeFields] forKey:@"fields"]; 94 | 95 | return jsonResult; 96 | } 97 | 98 | -(NSArray *) serializeFields { 99 | NSMutableArray *fieldsArr = [[NSMutableArray alloc] init]; 100 | for (NSUInteger i = 0; i <= SecurityVersion; ++i) { 101 | [fieldsArr addObject:[self.result getField:(MBUsdlKeys)i]]; 102 | } 103 | return fieldsArr; 104 | } 105 | 106 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBUsdlRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBUsdlRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBUsdlRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBUsdlRecognizerWrapper.h" 2 | 3 | #import "MBSerializationUtils.h" 4 | 5 | @implementation MBUsdlRecognizerCreator 6 | 7 | @synthesize jsonName = _jsonName; 8 | 9 | -(instancetype) init { 10 | self = [super init]; 11 | if (self) { 12 | _jsonName = @"UsdlRecognizer"; 13 | } 14 | return self; 15 | } 16 | 17 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 18 | MBUsdlRecognizer *recognizer = [[MBUsdlRecognizer alloc] init]; 19 | 20 | { 21 | id nullQuietZoneAllowed = [jsonRecognizer valueForKey:@"nullQuietZoneAllowed"]; 22 | if (nullQuietZoneAllowed != nil) { 23 | recognizer.allowNullQuietZone = [(NSNumber*)nullQuietZoneAllowed boolValue]; 24 | } 25 | } 26 | { 27 | id uncertainDecoding = [jsonRecognizer valueForKey:@"uncertainDecoding"]; 28 | if (uncertainDecoding != nil) { 29 | recognizer.scanUncertain = [(NSNumber*)uncertainDecoding boolValue]; 30 | } 31 | } 32 | { 33 | id enableCompactParser = [jsonRecognizer valueForKey:@"enableCompactParser"]; 34 | if (enableCompactParser != nil) { 35 | recognizer.enableCompactParser = [(NSNumber*)enableCompactParser boolValue]; 36 | } 37 | } 38 | 39 | return recognizer; 40 | } 41 | 42 | @end 43 | 44 | @interface MBUsdlRecognizer (JsonSerialization) 45 | @end 46 | 47 | @implementation MBUsdlRecognizer (JsonSerialization) 48 | 49 | -(NSDictionary *) serializeResult { 50 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 51 | 52 | [jsonResult setValue:self.result.firstName forKey:@"firstName"]; 53 | [jsonResult setValue:self.result.middleName forKey:@"middleName"]; 54 | [jsonResult setValue:self.result.lastName forKey:@"lastName"]; 55 | [jsonResult setValue:self.result.fullName forKey:@"fullName"]; 56 | [jsonResult setValue:self.result.nameSuffix forKey:@"nameSuffix"]; 57 | [jsonResult setValue:self.result.address forKey:@"address"]; 58 | [jsonResult setValue:self.result.documentNumber forKey:@"documentNumber"]; 59 | [jsonResult setValue:self.result.sex forKey:@"sex"]; 60 | [jsonResult setValue:self.result.restrictions forKey:@"restrictions"]; 61 | [jsonResult setValue:self.result.endorsements forKey:@"endorsements"]; 62 | [jsonResult setValue:self.result.vehicleClass forKey:@"vehicleClass"]; 63 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfBirth] forKey:@"dateOfBirth"]; 64 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfIssue] forKey:@"dateOfIssue"]; 65 | [jsonResult setValue:[MBSerializationUtils serializeMBDate:self.result.dateOfExpiry] forKey:@"dateOfExpiry"]; 66 | [jsonResult setValue:[NSNumber numberWithInteger:self.result.age] forKey:@"age"]; 67 | 68 | [jsonResult setValue:[self.result optionalElements] forKey:@"optionalElements"]; 69 | [jsonResult setValue:[[self.result data] base64EncodedStringWithOptions:0] forKey:@"rawData"]; 70 | [jsonResult setValue:[[NSString alloc] initWithData:[self.result data] encoding:NSUTF8StringEncoding] forKey:@"rawStringData"]; 71 | [jsonResult setValue:[NSNumber numberWithBool:[self.result isUncertain]] forKey:@"uncertain"]; 72 | [jsonResult setValue:[self serializeFields] forKey:@"fields"]; 73 | 74 | [jsonResult setValue:self.result.street forKey:@"street"]; 75 | [jsonResult setValue:self.result.postalCode forKey:@"postalCode"]; 76 | [jsonResult setValue:self.result.city forKey:@"city"]; 77 | [jsonResult setValue:self.result.jurisdiction forKey:@"jurisdiction"]; 78 | 79 | return jsonResult; 80 | } 81 | 82 | -(NSArray *) serializeFields { 83 | NSMutableArray *fieldsArr = [[NSMutableArray alloc] init]; 84 | for (NSUInteger i = 0; i <= SecurityVersion; ++i) { 85 | [fieldsArr addObject:[self.result getField:(MBUsdlKeys)i]]; 86 | } 87 | return fieldsArr; 88 | } 89 | 90 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBVisaRecognizerWrapper.h: -------------------------------------------------------------------------------- 1 | #import "MBRecognizerWrapper.h" 2 | #import 3 | 4 | @interface MBVisaRecognizerCreator : NSObject 5 | 6 | @end -------------------------------------------------------------------------------- /BlinkID/src/ios/MicroblinkModule/MicroblinkModule/Recognizers/Wrappers/MBVisaRecognizerWrapper.m: -------------------------------------------------------------------------------- 1 | #import "MBVisaRecognizerWrapper.h" 2 | #import "MBSerializationUtils.h" 3 | #import "MBBlinkIDSerializationUtils.h" 4 | #import "MBCommonSerializationUtils.h" 5 | 6 | @implementation MBVisaRecognizerCreator 7 | 8 | @synthesize jsonName = _jsonName; 9 | 10 | -(instancetype) init { 11 | self = [super init]; 12 | if (self) { 13 | _jsonName = @"VisaRecognizer"; 14 | } 15 | return self; 16 | } 17 | 18 | -(MBRecognizer *) createRecognizer:(NSDictionary*) jsonRecognizer { 19 | MBVisaRecognizer *recognizer = [[MBVisaRecognizer alloc] init]; 20 | { 21 | id detectGlare = [jsonRecognizer valueForKey:@"detectGlare"]; 22 | if (detectGlare != nil) { 23 | recognizer.detectGlare = [(NSNumber *)detectGlare boolValue]; 24 | } 25 | } 26 | { 27 | id faceImageDpi = [jsonRecognizer valueForKey:@"faceImageDpi"]; 28 | if (faceImageDpi != nil) { 29 | recognizer.faceImageDpi = [(NSNumber *)faceImageDpi integerValue]; 30 | } 31 | } 32 | { 33 | id fullDocumentImageDpi = [jsonRecognizer valueForKey:@"fullDocumentImageDpi"]; 34 | if (fullDocumentImageDpi != nil) { 35 | recognizer.fullDocumentImageDpi = [(NSNumber *)fullDocumentImageDpi integerValue]; 36 | } 37 | } 38 | { 39 | id fullDocumentImageExtensionFactors = [jsonRecognizer valueForKey:@"fullDocumentImageExtensionFactors"]; 40 | if (fullDocumentImageExtensionFactors != nil) { 41 | recognizer.fullDocumentImageExtensionFactors = [MBCommonSerializationUtils deserializeMBImageExtensionFactors:(NSDictionary*)fullDocumentImageExtensionFactors]; 42 | } 43 | } 44 | { 45 | id returnFaceImage = [jsonRecognizer valueForKey:@"returnFaceImage"]; 46 | if (returnFaceImage != nil) { 47 | recognizer.returnFaceImage = [(NSNumber *)returnFaceImage boolValue]; 48 | } 49 | } 50 | { 51 | id returnFullDocumentImage = [jsonRecognizer valueForKey:@"returnFullDocumentImage"]; 52 | if (returnFullDocumentImage != nil) { 53 | recognizer.returnFullDocumentImage = [(NSNumber *)returnFullDocumentImage boolValue]; 54 | } 55 | } 56 | 57 | return recognizer; 58 | } 59 | 60 | @end 61 | 62 | @interface MBVisaRecognizer (JsonSerialization) 63 | @end 64 | 65 | @implementation MBVisaRecognizer (JsonSerialization) 66 | 67 | -(NSDictionary *) serializeResult { 68 | NSMutableDictionary* jsonResult = (NSMutableDictionary*)[super serializeResult]; 69 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.faceImage] forKey:@"faceImage"]; 70 | [jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.fullDocumentImage] forKey:@"fullDocumentImage"]; 71 | [jsonResult setValue:[MBBlinkIDSerializationUtils serializeMrzResult:self.result.mrzResult] forKey:@"mrzResult"]; 72 | 73 | return jsonResult; 74 | } 75 | 76 | @end -------------------------------------------------------------------------------- /COPYRIGHT.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016. Microblink LLC 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlinkID SDK wrapper for React Native 2 | 3 | Best-in-class ID scanning software for cross-platform apps built with React Native. 4 | 5 | Below, you’ll find a quick guide on starting your own demo project as well as complete guidance on installing and linking BlinkID library with your iOS and Android apps ⬇️ 6 | 7 | For a full access to all features and functionalities, please consider using our native SDKs (for [iOS](https://github.com/BlinkID/blinkid-ios) or [Android](https://github.com/BlinkID/blinkid-android)) 8 | 9 | 10 | ## Licensing 11 | 12 | - A valid license key is required to initialize scanning. You can request a **free trial license key**, after you register, at [Microblink Developer Hub](https://account.microblink.com/signin) 13 | 14 | - For production licensing, please [contact sales](https://microblink.com/contact-us) to request a quote. 15 | 16 | **Keep in mind:** Versions 5.8.0 and above require an internet connection to work under our new License Management Program. 17 | 18 | We’re only asking you to do this so we can validate your trial license key. Scanning or data extraction of identity documents still happens offline, on the device itself. 19 | 20 | Once the validation is complete, you can continue using the SDK in offline mode (or over a private network) until the next check. 21 | 22 | 23 | ## React Native Version 24 | 25 | BlinkID React Native was built and tested with [React Native v0.75.0](https://github.com/facebook/react-native/releases/tag/v0.75.0) 26 | 27 | ## Installation 28 | 29 | First generate an empty project if needed: 30 | 31 | ```shell 32 | react-native init --version="0.75.0" NameOfYourProject 33 | ``` 34 | 35 | Add the **blinkid-react-native** module to your project: 36 | 37 | ```shell 38 | cd 39 | npm i --save blinkid-react-native 40 | ``` 41 | 42 | ## Linking 43 | 44 | ### iOS 45 | 46 | Link module with your project: 47 | 48 | ```shell 49 | react-native link blinkid-react-native 50 | ``` 51 | 52 | [CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like BlinkID in your projects. 53 | 54 | - If you wish to use version v1.4.0 or above, you need to install [Git Large File Storage](https://git-lfs.github.com) by running these comamnds: 55 | 56 | ```shell 57 | brew install git-lfs 58 | git lfs install 59 | ``` 60 | 61 | - **Be sure to restart your console after installing Git LFS** 62 | 63 | #### Installing pods 64 | 65 | From [react-native 0.60](https://facebook.github.io/react-native/blog/2019/07/03/version-60#cocoapods-by-default) CocoaPods are now part of React Native's iOS project. 66 | 67 | Go to `NameOfYourProject/ios` folder and install Pods 68 | 69 | ```shell 70 | pod install 71 | ``` 72 | 73 | Our `blinkid-react-native` depends on latest `PPBlinkID` pod so it will be installed automatically. 74 | 75 | **To run iOS application, open NameOfYourProject.xcworkspace, set Your team for every Target in General settings and add Privacy - Camera Usage Description key to Your info.plist file and press run** 76 | 77 | ### Android 78 | 79 | Add microblink maven repository to project level build.gradle: 80 | 81 | ``` 82 | allprojects { 83 | repositories { 84 | // don't forget to add maven and jcenter 85 | mavenLocal() 86 | jcenter() 87 | 88 | // ... other repositories your project needs 89 | 90 | maven { url "http://maven.microblink.com" } 91 | } 92 | } 93 | ``` 94 | 95 | ## Sample 96 | 97 | This repository contains **initReactNativeSampleApp.sh** script that will create React Native project and download all of its dependencies. You can run this script with following command: 98 | ```shell 99 | ./initReactNativeSampleApp.sh 100 | ``` 101 | 102 | ## Video tutorial 103 | 104 | Step by step guide how to start blinkid-reactnative sample app. A tutorial flows from cloning repository via git clone to successfully deployed sample application on Android and iOS device with real-time screen mirroring. Application sample contains the simple use of USDL recognizer with Ontario drivers license card. 105 | 106 |

107 | 108 | Video tutorial 109 | 110 | Watch on Vimeo 111 |

112 | 113 | ### Using documentVerificationOverlay and CombinedRecognizer 114 | 115 | This video tutorial describes how to use documentVerificationOverlay with UsdlCombinedRecognizer. 116 | DocumentVerificationOverlay is overlay for RecognizerRunnerFragment best suited for combined recognizers because it manages scanning of multiple document sides in the single camera opening and guides the user through the scanning process. It can also be used for single side scanning of ID cards, passports, driver’s licenses, etc 117 | 118 |

119 | 120 | Video tutorial 121 | 122 | Watch on Vimeo 123 |

124 | 125 | ## Usage 126 | 127 | To use the module you call it in your index.android.js or index.ios.js file like in the [sample app](sample_files/index.js). Available recognizers and API documentation is available in [JS API files](BlinkID). 128 | 129 | ## FAQ 130 | 131 | **Can I create a custom UI overlay?** 132 | 133 | Yes you can, but you will have to implement it natively for android and ios, you can see native implementation guides [here(Android)](https://github.com/BlinkID/blinkid-android#recognizerRunnerView) and [here(ios)](https://github.com/BlinkID/blinkid-ios#recognizerRunnerViewController). 134 | 135 | ## Known react-native problems: 136 | 137 | ### iOS 138 | React native v0.62.2 139 | 140 | ** [NSURLResponse allHeaderFields]: unrecognized selector sent to instance** 141 | 142 | Make sure to use the Flipper version 0.37.0 in your Podfile: 143 | 144 | `versions['Flipper'] ||= '~> 0.37.0'` 145 | 146 | ### Android build exception - missing `ReactSwipeRefreshLayout` 147 | 148 | **java.lang.NoClassDefFoundError: com.facebook.react.views.swiperefresh.ReactSwipeRefreshLayout** 149 | 150 | Add the following line to dependencies section in android/app/build.gradle: 151 | 152 | `implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'` 153 | 154 | -------------------------------------------------------------------------------- /initReactNativeSampleApp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | blink_id_plugin_path=`pwd`/BlinkID 4 | appName=Sample 5 | 6 | # remove any existing code 7 | rm -rf $appName 8 | 9 | # create a sample application 10 | # https://github.com/react-native-community/cli#using-npx-recommended 11 | npx @react-native-community/cli init $appName --version="0.75" || exit 1 12 | 13 | # enter into demo project folder 14 | pushd $appName || exit 1 15 | 16 | IS_LOCAL_BUILD=false || exit 1 17 | if [ "$IS_LOCAL_BUILD" = true ]; then 18 | echo "Using blinkid-react-native from this repo instead from NPM" 19 | # use directly source code from this repo instead of npm package 20 | # from RN 0.57 symlink does not work any more 21 | npm pack $blink_id_plugin_path 22 | npm install --save blinkid-react-native-6.13.1.tgz 23 | #pushd node_modules 24 | #ln -s $blink_id_plugin_path blinkid-react-native 25 | #popd 26 | else 27 | # download npm package 28 | echo "Downloading blinkid-react-native module" 29 | npm install --save blinkid-react-native 30 | fi 31 | 32 | # react-native-image-picker plugin needed only for sample application with DirectAPI to get the document images 33 | npm install react-native-image-picker 34 | 35 | # Auto-linking is done in 0.6 versions 36 | 37 | # enter into android project folder 38 | pushd android || exit 1 39 | 40 | # patch the build.gradle to add "maven { url https://maven.microblink.com }"" repository 41 | perl -i~ -pe "BEGIN{$/ = undef;} s/maven \{/maven \{ url 'https:\\/\\/maven.microblink.com' }\n maven {/" build.gradle 42 | 43 | # change package name 44 | # adb uninstall "com.microblink.sample" 45 | mkdir -p app/src/main/java/com/microblink/sample 46 | mkdir -p app/src/debug/java/com/microblink/sample 47 | mv app/src/main/java/com/sample/* app/src/main/java/com/microblink/sample/ 48 | mv app/src/debug/java/com/sample/* app/src/debug/java/com/microblink/sample/ 49 | rmdir app/src/main/java/com/sample 50 | rmdir app/src/debug/java/com/sample 51 | grep -rl com.sample . | xargs sed -i '' s/com.sample/com.microblink.sample/g 52 | ./gradlew clean 53 | 54 | # return from android project folder 55 | popd 56 | 57 | # enter into ios project folder 58 | pushd ios || exit 1 59 | 60 | #Force minimal iOS version 61 | #sed -i '' "s/platform :ios, min_ios_version_supported/platform :ios, '13.0'/" Podfile 62 | 63 | # install pod 64 | pod install 65 | 66 | # if [ "$IS_LOCAL_BUILD" = true ]; then 67 | # echo "Replace pod with custom dev version of BlinkID framework" 68 | # replace pod with custom dev version of BlinkID framework 69 | # pushd Pods/PPBlinkID || exit 1 70 | # rm -rf Microblink.bundle 71 | # rm -rf Microblink.framework 72 | # cp -r ~/Downloads/blinkid-ios/Microblink.framework ./ 73 | # popd 74 | # fi 75 | 76 | # change bundle id 77 | sed -i '' s/\$\(PRODUCT_BUNDLE_IDENTIFIER\)/com.microblink.sample/g $appName/Info.plist 78 | 79 | #Disable Flipper since it spams console with errors 80 | export NO_FLIPPER=1 81 | 82 | pod install 83 | 84 | # return from ios project folder 85 | popd 86 | 87 | # remove index.js 88 | rm -f index.js 89 | 90 | # remove index.ios.js 91 | rm -f index.ios.js 92 | 93 | # remove index.android.js 94 | rm -f index.android.js 95 | 96 | cp ../sample_files/index.js ./ 97 | 98 | # use the same index.js file for Android and iOS 99 | cp index.js index.ios.js 100 | cp index.js index.android.js 101 | 102 | # return to root folder 103 | popd 104 | 105 | echo "Go to React Native project folder: cd $appName" 106 | echo "To run on Android execute: npx react-native run-android" 107 | echo "To run on iOS: 108 | 1. Open $appName/ios/$appName.xcworkspace 109 | 2. Set your development team 110 | 3. Add the NSCameraUsageDescription & NSPhotoLibraryUsageDescription keys to your Info.plist file 111 | 4. Press run" 112 | -------------------------------------------------------------------------------- /publish.sh: -------------------------------------------------------------------------------- 1 | FOLDER='BlinkID' 2 | 3 | pushd $FOLDER > /dev/null || exit 1 4 | 5 | # copy README.md to npm package folder 6 | cp ../README.md . || exit 1 7 | 8 | # publish to npm 9 | npm publish 10 | 11 | # rm README.md 12 | rm README.md 13 | 14 | popd > /dev/null 15 | --------------------------------------------------------------------------------