From 8e17e3184d4d02b5b812c5bc195b40f2dad7a316 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 17 Feb 2016 11:00:47 +1100 Subject: [PATCH] wait until viewController is dismissed before callback, fixes #47 --- ios/CsZBar.m | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ios/CsZBar.m b/ios/CsZBar.m index 6df2520..a7a61f7 100644 --- a/ios/CsZBar.m +++ b/ios/CsZBar.m @@ -104,29 +104,32 @@ ZBarSymbol *symbol = nil; for(symbol in results) break; // get the first result - [self.scanReader dismissModalViewControllerAnimated: YES]; - self.scanInProgress = NO; - [self sendScanResult: [CDVPluginResult - resultWithStatus: CDVCommandStatus_OK - messageAsString: symbol.data]]; + [self.scanReader dismissViewControllerAnimated: YES completion: ^(void) { + self.scanInProgress = NO; + [self sendScanResult: [CDVPluginResult + resultWithStatus: CDVCommandStatus_OK + messageAsString: symbol.data]]; + }]; } - (void) imagePickerControllerDidCancel:(UIImagePickerController*)picker { - [self.scanReader dismissModalViewControllerAnimated: YES]; - self.scanInProgress = NO; - [self sendScanResult: [CDVPluginResult - resultWithStatus: CDVCommandStatus_ERROR - messageAsString: @"cancelled"]]; + [self.scanReader dismissViewControllerAnimated: YES completion: ^(void) { + self.scanInProgress = NO; + [self sendScanResult: [CDVPluginResult + resultWithStatus: CDVCommandStatus_ERROR + messageAsString: @"cancelled"]]; + }]; } - (void) readerControllerDidFailToRead:(ZBarReaderController*)reader withRetry:(BOOL)retry { - [self.scanReader dismissModalViewControllerAnimated: YES]; - self.scanInProgress = NO; - [self sendScanResult: [CDVPluginResult - resultWithStatus: CDVCommandStatus_ERROR - messageAsString: @"Failed"]]; + [self.scanReader dismissViewControllerAnimated: YES completion: ^(void) { + self.scanInProgress = NO; + [self sendScanResult: [CDVPluginResult + resultWithStatus: CDVCommandStatus_ERROR + messageAsString: @"Failed"]]; + }]; }