Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #170 from jcesarmobile/callback-with-blocks
Browse files Browse the repository at this point in the history
send callbacks on dismissViewControllerAnimated completion
  • Loading branch information
jcesarmobile committed Jun 23, 2016
2 parents d92af72 + 21152cf commit ae9f6e2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/ios/CDVBarcodeScanner.mm
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ae9f6e2

Please sign in to comment.