2

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);
Deepak Thakur
  • 3,453
  • 2
  • 37
  • 65
  • Hello , How to solve your problem – Deepesh Nov 14 '13 at 13:16
  • @Deepesh I entered the code in a self made method [self startCameraToScan] in the selected segment AS WELL AS in viewDidLoad. So this method is invoked on the tab. So startCameraToScan will have the code instead of viewWillAppear – Deepak Thakur Nov 14 '13 at 13:22

1 Answers1

0

Move your code to

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

Instead of viewWillAppear.

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

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71