Hi I'm developing a QR code reader app and having so much trouble when dismissing the ZBarReaderViewController. I have a view controller with a button which creates the reader and presents it.
- (IBAction)scanAction:(id)sender {
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
[reader.scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader.readerView.zoom = 1.0;
// [self presentViewController:reader animated:YES completion:nil];
[self presentModalViewController:reader animated:YES];
}
Then on the reader's delegate I'm doing this (I commented the results processing lines but I still get the same error):
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
//
// ZBarSymbol *symbol = nil;
// NSURL *url;
// NSString * textUrl;
//
// for(symbol in results){
// textUrl = symbol.data;
// NSLog(@"%@",textUrl);
// url = [NSURL URLWithString:textUrl];
// break;
// }
//
// if (url != nil) {
//// NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//// [self.webView loadRequest:requestObj];
// [self.urlLabel setText:textUrl];
// }
// [reader dismissViewControllerAnimated:NO completion:nil];
[reader dismissModalViewControllerAnimated:YES];
}
and this is the error I get randomly:
QR reader[10159:907] Warning: Attempt to dismiss from view controller <ViewController: 0x1ed4c930> while a presentation or dismiss is in progress!
Sometimes it scans and dismiss without any warning but when I get that warning the reader stays scanning, and the delegate gets called again until no more warnings are showed.
I tried some suggestions from other users having the same problem but it won't work in my particular case:
- using dismissModalViewController instead of modal view which is deprecated.
- sorrounding the results processing in the completion block of the dismissViewControllerAnimated method.
Thanks for reading :)