iOS : ZBarCode reader not working on custom UISegmentedControl click

739 views Asked by At

I followed this tutorial to implement zbarcode reader in my iOS application. Since I am using custom UISegmentedControl, the camera should start immediately on that segment click and start scanning the QR code. Camera is starting up, but the red line is missing and hence not scanning the QR code.

I get this warning inside the log which mentions

Warning: Attempt to present <ZBarReaderViewController: 0x7befb50> on <UINavigationController: 0x7b6f950> while a presentation is in progress!

I wrote the button logic in viewWill load of ScanViewController segment. Using Xcode 4.6 and testing in iPad 2. Here's my code

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    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
    resultText.text = symbol.data;

    // EXAMPLE: do something useful with the barcode image
    resultImage.image =
    [info objectForKey: UIImagePickerControllerOriginalImage];

    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissModalViewControllerAnimated: YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"Starting Camera to scan QR Code...");
    // ADD: present a barcode reader that scans from the camera feed
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    // present and release the controller
    [self presentModalViewController: reader
                            animated: YES];

    NSString *checkURL = self.resultText.text;
    NSLog(@"Checking URL scanned from QR Code before passing to List :: %@", checkURL);
1

There are 1 answers

0
Grzegorz Krukowski On

Move your code to

- (void) viewDidAppear:(BOOL) animate { }

Instead of viewWillAppear.

Problem is you are trying to presentModalViewController before the view appeared.