1

I want to create application for Scan Books barcode , but when I can scan barcode successfully , then ZBarReaderViewController not dismiss in imagePickerController didFinishPickingMediaWithInfo delegate and I getting warning :

Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;
    // EXAMPLE: do something useful with the barcode data
    resultLable.text = symbol.data;
    isbnResultString=symbol.data;
    NSLog(@"isbnResultString-----%@",isbnResultString);
    isbnLableText.text=isbnResultString;
    NSLog(@"%@",[info objectForKey: UIImagePickerControllerOriginalImage]);
    // EXAMPLE: do something useful with the barcode image
    barCodeImageView.image=[info objectForKey: UIImagePickerControllerOriginalImage];
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [self dismissViewControllerAnimated:YES completion:nil];

    if (isbnResultString.length!=0)
    {
        if(![self connectedToInternet])
        {
            [appDelagate showActivityIndicator];
            appDelagate.isNetConnected=NO;
            [self internetAlert];
        }
        else
        {
            [self getBookDetailsByISBN:symbol.data];
        }
    }
}

How to dismiss ZBarReaderViewController?

Cœur
  • 37,241
  • 25
  • 195
  • 267
vijay
  • 1,235
  • 1
  • 11
  • 32

1 Answers1

1

Had the same issue and performSeletor:withObject:afterDelay: works fine for me.

- (void)imagePickerController:(UIImagePickerController *)reader didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // do some userful stuff

    [self performSelector:@selector(dismissZBar) withObject:nil afterDelay:1];
}

- (void)dismissZBar {
    [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
        // do some stuff after dismiss
    }];
}