@@ -35,6 +35,8 @@ @interface ALPluginScanViewController () <ALScanPluginDelegate, ALViewPluginComp
35
35
// / Applicable to non-composites (otherwise null)
36
36
@property (nonatomic , readonly , nullable ) ALPluginConfig *pluginConfig;
37
37
38
+ @property (nonatomic , strong ) NSError *scanViewError;
39
+
38
40
@end
39
41
40
42
@@ -82,8 +84,9 @@ - (void)viewDidLoad {
82
84
error: &error];
83
85
84
86
if ([self showErrorAlertIfNeeded: error]) {
85
- return ;
86
- }
87
+ self.scanViewError = error;
88
+ return ;
89
+ }
87
90
88
91
[self .view addSubview: self .scanView];
89
92
@@ -118,8 +121,15 @@ - (void)viewDidAppear:(BOOL)animated {
118
121
[UIApplication sharedApplication ].idleTimerDisabled = YES ;
119
122
120
123
NSError *error;
121
- [self .scanView.scanViewPlugin startWithError: &error];
122
- [self showErrorAlertIfNeeded: error];
124
+ if (!self.scanViewError ){
125
+ [self .scanView.viewPlugin startWithError: &error];
126
+ [self showErrorAlertIfNeeded: error];
127
+ }
128
+ else {
129
+ [self dismissViewControllerAnimated: YES completion: ^{
130
+ self.callback (nil , self.scanViewError );
131
+ }];
132
+ }
123
133
}
124
134
125
135
- (void )viewDidDisappear : (BOOL )animated {
@@ -200,7 +210,7 @@ - (void)handleResult:(id _Nullable)resultObj {
200
210
}
201
211
202
212
// dismiss the view controller, if cancelOnResult for the config is true
203
- NSObject <ALScanViewPluginBase > *scanViewPluginBase = self.scanView .scanViewPlugin ;
213
+ NSObject <ALViewPluginBase > *scanViewPluginBase = self.scanView .viewPlugin ;
204
214
if ([scanViewPluginBase isKindOfClass: ALScanViewPlugin.class]) {
205
215
ALScanViewPlugin *scanViewPlugin = (ALScanViewPlugin *)scanViewPluginBase;
206
216
BOOL cancelOnResult = scanViewPlugin.scanPlugin .pluginConfig .cancelOnResult ;
@@ -289,7 +299,7 @@ - (void)scanView:(ALScanView *)scanView didReceiveNativeBarcodeResult:(ALScanRes
289
299
290
300
- (ALPluginConfig * _Nullable)pluginConfig {
291
301
// applic. only to non-composites
292
- NSObject <ALScanViewPluginBase > *scanVwPluginBase = self.scanView .scanViewPlugin ;
302
+ NSObject <ALViewPluginBase > *scanVwPluginBase = self.scanView .viewPlugin ;
293
303
if ([scanVwPluginBase isKindOfClass: ALScanViewPlugin.class]) {
294
304
return ((ALScanViewPlugin *)scanVwPluginBase).scanPlugin .pluginConfig ;
295
305
}
@@ -299,11 +309,11 @@ - (ALPluginConfig * _Nullable)pluginConfig {
299
309
// MARK: - Selector Actions
300
310
301
311
- (void )doneButtonPressed : (id )sender {
302
- [self .scanView.scanViewPlugin stop ];
312
+ [self .scanView.viewPlugin stop ];
303
313
304
314
__weak __block typeof (self) weakSelf = self;
305
315
[self dismissViewControllerAnimated: YES completion: ^{
306
- weakSelf.callback (nil , @" Canceled" );
316
+ weakSelf.callback (nil , [ NSError errorWithDomain: @" ALReactDomain " code: - 1 userInfo: @{ NSLocalizedDescriptionKey : @" Canceled" }] );
307
317
}];
308
318
}
309
319
@@ -356,25 +366,23 @@ - (void)updateScanModeWithValue:(NSString *)modeString {
356
366
357
367
// assume that pluginConfig carries the updated scanMode or whatever value that you wish to refresh.
358
368
- (BOOL )updatePluginConfig : (ALPluginConfig *)pluginConfig error : (NSError * _Nullable * _Nullable)error {
359
- ALScanViewPluginConfig *origSVPConfig = ((ALScanViewPlugin *)self.scanView .scanViewPlugin ).scanViewPluginConfig ;
360
- ALScanViewPluginConfig *scanViewPluginConfig = [ALScanViewPluginConfig withPluginConfig: pluginConfig
361
- cutoutConfig: origSVPConfig.cutoutConfig
362
- scanFeedbackConfig: origSVPConfig.scanFeedbackConfig];
363
- ALScanViewPlugin *newScanViewPlugin = [[ALScanViewPlugin alloc ] initWithConfig: scanViewPluginConfig error: error];
364
- if (!newScanViewPlugin) {
365
- return NO ;
366
- }
367
-
368
- newScanViewPlugin.scanPlugin .delegate = self;
369
+ ALViewPluginConfig *origSVPConfig = ((ALScanViewPlugin *)self.scanView .viewPlugin ).scanViewPluginConfig ;
369
370
370
- BOOL success = [self .scanView setScanViewPlugin: newScanViewPlugin error: error];
371
+ origSVPConfig.pluginConfig = pluginConfig;
372
+ BOOL success = [self .scanView setViewPluginConfig: origSVPConfig error: error];
371
373
if (!success) {
374
+ if ([self showErrorAlertIfNeeded: *error]){
375
+ [self dismissOnError: *error];
376
+ }
372
377
return NO ;
373
378
}
374
379
375
- success = [[ self .scanView scanViewPlugin ] startWithError: error];
380
+ success = [self .scanView.viewPlugin startWithError: error];
376
381
if (!success) {
377
382
// check error
383
+ if ([self showErrorAlertIfNeeded: *error]){
384
+ [self dismissOnError: *error];
385
+ }
378
386
return NO ;
379
387
}
380
388
return YES ;
@@ -429,7 +437,18 @@ - (BOOL)segmentModesAreValid {
429
437
// MARK: - Miscellaneous
430
438
431
439
- (BOOL )showErrorAlertIfNeeded : (NSError *)error {
432
- return [ALPluginHelper showErrorAlertIfNeeded: error pluginCallback: self .callback];
440
+ if (!error) {
441
+ return NO ;
442
+ }
443
+
444
+ return YES ;
433
445
}
434
446
447
+ -(void )dismissOnError : (NSError *)error {
448
+ [self dismissViewControllerAnimated: YES completion: ^{
449
+ self.callback (nil , error);
450
+ }];
451
+ }
452
+
453
+
435
454
@end
0 commit comments