bharath
bharath

Reputation: 953

zbar IOS screen freezes

I am integrating zbar in my iphone application and below is the code for scanning the barcode.

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

[self presentModalViewController: reader
                            animated: YES];

On completion, i will do the following.

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)

        break;
    // Do what ever u want
    [reader dismissModalViewControllerAnimated: YES];
}

The problem with this is, i am using IOS7 and its scanning perfectly in the first instance, however, for the second instance, after it scans, it wont proceed further, even the cancel button wont work and the screen remains in camera mode. I read its an issue with cpu and memory for IOS7 but could not figure out how it can be rectified in my case. Kindly give your valuable inputs.

Upvotes: 1

Views: 578

Answers (1)

Mario
Mario

Reputation: 2505

Okay, first, please ignore the comment I made about subclassing ZBarReaderView. It was a while ago that I was having problems, and even though I remember trying that, that was not the solution I settled for. I have a couple of suggestions for you.

In the bit of code on top after presentViewController:animated: try setting the pointer to the reader to nil. I do the following:

[self presentViewController:reader animated:YES completion:nil];
reader = nil;

The view controller you're presenting will be holding onto the reader, so don't worry about losing the reference. I think this actually helps with memory. (And, when you're having a problem where things work at first and then fail after doing them more than once, that's often a memory issue.)

Apart from that, in the top bit, I turn off all the symbols, and then enable only the ones I'm interested in. For example, I might do something like this:

// Enable only ISBN-13 & ISBN-10 barcodes
[scanner setSymbology:0 config:ZBAR_CFG_ENABLE to:0];
[scanner setSymbology:ZBAR_EAN13 config:ZBAR_CFG_ENABLE to:1];
[scanner setSymbology:ZBAR_ISBN10 config:ZBAR_CFG_ENABLE to:1];

Give these two suggestions a try, especially the first one about setting the reference to nil. That may help.

Upvotes: 1

Related Questions