From 21152cf42978623ae6c67488124fb6474342f9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Fri, 12 Feb 2016 20:50:55 +0100 Subject: [PATCH] send callbacks on dismissViewControllerAnimated completion Changed barcodeScanDone method to use a block, so it sends the callbacks to the javascript side when the barcode scanner view controller has been completely dismissed. It was causing problems with the dialogs plugin if you used a dialog on the success or error callback --- src/ios/CDVBarcodeScanner.mm | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ios/CDVBarcodeScanner.mm b/src/ios/CDVBarcodeScanner.mm index 0c5011bf..b95d8917 100644 --- a/src/ios/CDVBarcodeScanner.mm +++ b/src/ios/CDVBarcodeScanner.mm @@ -336,11 +336,11 @@ - (void)openDialog { } //-------------------------------------------------------------------------- -- (void)barcodeScanDone { +- (void)barcodeScanDone:(void (^)(void))callbackBlock { self.capturing = NO; [self.captureSession stopRunning]; - [self.parentViewController dismissViewControllerAnimated: YES completion:nil]; - + [self.parentViewController dismissViewControllerAnimated:YES completion:callbackBlock]; + // viewcontroller holding onto a reference to us, release them so they // will release us self.viewController = nil; @@ -380,22 +380,25 @@ - (BOOL)checkResult:(NSString *)result { //-------------------------------------------------------------------------- - (void)barcodeScanSucceeded:(NSString*)text format:(NSString*)format { dispatch_sync(dispatch_get_main_queue(), ^{ - [self barcodeScanDone]; + [self barcodeScanDone:^{ + [self.plugin returnSuccess:text format:format cancelled:FALSE flipped:FALSE callback:self.callback]; + }]; AudioServicesPlaySystemSound(_soundFileObject); - [self.plugin returnSuccess:text format:format cancelled:FALSE flipped:FALSE callback:self.callback]; }); } //-------------------------------------------------------------------------- - (void)barcodeScanFailed:(NSString*)message { - [self barcodeScanDone]; - [self.plugin returnError:message callback:self.callback]; + [self barcodeScanDone:^{ + [self.plugin returnError:message callback:self.callback]; + }]; } //-------------------------------------------------------------------------- - (void)barcodeScanCancelled { - [self barcodeScanDone]; - [self.plugin returnSuccess:@"" format:@"" cancelled:TRUE flipped:self.isFlipped callback:self.callback]; + [self barcodeScanDone:^{ + [self.plugin returnSuccess:@"" format:@"" cancelled:TRUE flipped:self.isFlipped callback:self.callback]; + }]; if (self.isFlipped) { self.isFlipped = NO; }