33#import " MBCOverlaySettingsSerializers.h"
44#import " MBCRecognizerWrapper.h"
55#import " MBCSerializationUtils.h"
6-
76#import < Foundation/Foundation.h>
87#import " MBCBlinkCardModule.h"
98#import < React/RCTConvert.h>
@@ -19,12 +18,13 @@ typedef NS_ENUM(NSUInteger, PPImageType) {
1918static NSString * const MBCErrorDomain = @" microblink.error" ;
2019static NSString * const RESULT_CAPTURED_FULL_IMAGE = @" capturedFullImage" ;
2120static NSString * const RESULT_DOCUMENT_CAPTURE_RECOGNIZER_RESULT = @" documentCaptureRecognizerResult" ;
22-
2321@interface MBCBlinkCardModule () <MBCOverlayViewControllerDelegate, MBCScanningRecognizerRunnerDelegate, MBCFirstSideFinishedRecognizerRunnerDelegate>
2422
2523@property (nonatomic , strong ) MBCRecognizerCollection *recognizerCollection;
2624@property (nonatomic ) id <MBCRecognizerRunnerViewController> scanningViewController;
2725@property (nonatomic , strong ) MBCRecognizerRunner *recognizerRunner;
26+ @property (nonatomic , strong ) MBCOverlayViewController *overlayVc;
27+ @property (nonatomic , strong ) NSDictionary *recognizerCollectionDict;
2828@property (nonatomic , strong ) NSDictionary *backImageBase64Image;
2929
3030@property (class , nonatomic , readonly ) NSString *STATUS_SCAN_CANCELED;
@@ -55,7 +55,7 @@ + (BOOL)requiresMainQueueSetup {
5555
5656/* *
5757 Method sanitizes the dictionary replaces all occurances of NSNull with nil
58-
58+
5959 @param dictionary JSON objects
6060 @return new dictionary with NSNull values replaced with nil
6161 */
@@ -70,26 +70,27 @@ - (NSDictionary *)sanitizeDictionary:(NSDictionary *)dictionary {
7070}
7171
7272RCT_REMAP_METHOD (scanWithCamera, scanWithCamera:(NSDictionary *)jsonOverlaySettings recognizerCollection:(NSDictionary *)jsonRecognizerCollection license:(NSDictionary *)jsonLicense resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
73-
73+
7474 // Sanitize the dictionaries
7575 jsonOverlaySettings = [self sanitizeDictionary: jsonOverlaySettings];
7676 jsonRecognizerCollection = [self sanitizeDictionary: jsonRecognizerCollection];
77+ _recognizerCollectionDict = jsonRecognizerCollection;
7778 jsonLicense = [self sanitizeDictionary: jsonLicense];
7879
7980 self.promiseResolve = resolve;
8081 self.promiseReject = reject;
8182
8283 if ([self setupLicense: jsonLicense]) {
8384 [self setupLanguage: jsonOverlaySettings];
84-
85+
8586 self.recognizerCollection = [[MBCRecognizerSerializers sharedInstance ] deserializeRecognizerCollection: jsonRecognizerCollection];
86-
8787 dispatch_sync (dispatch_get_main_queue (), ^{
88- MBCOverlayViewController *overlayVC = [[MBCOverlaySettingsSerializers sharedInstance ] createOverlayViewController: jsonOverlaySettings recognizerCollection: self .recognizerCollection delegate: self ];
89-
90- UIViewController<MBCRecognizerRunnerViewController>* recognizerRunnerViewController = [MBCViewControllerFactory recognizerRunnerViewControllerWithOverlayViewController: overlayVC];
88+ _overlayVc = [[MBCOverlaySettingsSerializers sharedInstance ] createOverlayViewController: jsonOverlaySettings recognizerCollection: self .recognizerCollection delegate: self ];
89+
90+ UIViewController<MBCRecognizerRunnerViewController>* recognizerRunnerViewController = [MBCViewControllerFactory recognizerRunnerViewControllerWithOverlayViewController: _overlayVc];
91+ [recognizerRunnerViewController setModalPresentationStyle: UIModalPresentationFullScreen];
9192 self.scanningViewController = recognizerRunnerViewController;
92-
93+
9394 UIViewController *rootViewController = [[[UIApplication sharedApplication ] keyWindow ] rootViewController ];
9495 [rootViewController presentViewController: self .scanningViewController animated: YES completion: nil ];
9596 });
@@ -125,25 +126,25 @@ - (void)overlayViewControllerDidFinishScanning:(MBCOverlayViewController *)overl
125126 if (state != MBCRecognizerResultStateEmpty) {
126127 [overlayViewController.recognizerRunnerViewController pauseScanning ];
127128 // recognizers within self.recognizerCollection now have their results filled
128-
129+
129130 BOOL isDocumentCaptureRecognizer = NO ;
130-
131+
131132 NSMutableArray *jsonResults = [[NSMutableArray alloc ] initWithCapacity: self .recognizerCollection.recognizerList.count];
132-
133+
133134 for (NSUInteger i = 0 ; i < self.recognizerCollection .recognizerList .count ; ++i) {
134135 [jsonResults addObject: [[self .recognizerCollection.recognizerList objectAtIndex: i] serializeResult ]];
135-
136- if (!isDocumentCaptureRecognizer) {
137- self.promiseResolve (jsonResults);
138- }
139- // dismiss recognizer runner view controller
140- dispatch_async (dispatch_get_main_queue (), ^{
141- UIViewController *rootViewController = [[[UIApplication sharedApplication ] keyWindow ] rootViewController ];
142- [rootViewController dismissViewControllerAnimated: YES completion: nil ];
143- self.recognizerCollection = nil ;
144- self.scanningViewController = nil ;
145- self.promiseResolve = nil ;
146- self.promiseReject = nil ;
136+
137+ if (!isDocumentCaptureRecognizer) {
138+ self.promiseResolve (jsonResults);
139+ }
140+ // dismiss recognizer runner view controller
141+ dispatch_async (dispatch_get_main_queue (), ^{
142+ UIViewController *rootViewController = [[[UIApplication sharedApplication ] keyWindow ] rootViewController ];
143+ [rootViewController dismissViewControllerAnimated: YES completion: nil ];
144+ self.recognizerCollection = nil ;
145+ self.scanningViewController = nil ;
146+ self.promiseResolve = nil ;
147+ self.promiseReject = nil ;
147148 });
148149 }
149150 }
@@ -158,7 +159,7 @@ - (void)overlayDidTapClose:(MBCOverlayViewController *)overlayViewController {
158159 code: -58
159160 userInfo: nil ];
160161 self.promiseReject (MBCBlinkCardModule.STATUS_SCAN_CANCELED , @" Scanning has been canceled" , error);
161-
162+
162163 self.promiseResolve = nil ;
163164 self.promiseReject = nil ;
164165}
0 commit comments