Question

We're using version 1.2 (and trying beta 1.3.1) of the ZBarSDK for reading barcodes in our app. We have been using this code for some time with no problems in iOS 5 and 6, but iOS 7 appears to have some issues initializing the camera. When we call the start method in the ZBarReaderView it takes 30 to 60 seconds or even longer to initialize the camera. The user sees a black camera view that whole time and they are wondering if the app works.

Once the view is initialized we can close it and reopen it any number of times with no issues and it opens rapidly.

Here is the relevant part of our code:

- (void)showAnimated:(BOOL)animated
{
    [self.controller overlayWillShow:self];
    dispatch_async(dispatch_queue_create(0, 0), ^{[self.zBarReaderView start];});
    CGRect frame = self.superview.frame;
    frame.origin.y = -hiddenYOrigin;
    [UIView animateWithDuration:0.4 animations:^{
        self.superview.frame = frame;
    } completion:^(BOOL finished){
        if (((ScanController *)self.controller).scanMode == ScanModeManualEntry) {
            [self.manualEntryTextField becomeFirstResponder];
        }
        self.showing = YES;
        [self.controller overlayDidShow:self];
    }];
}

All of that code executes rapidly, but the dispatch_queue_create call to ZBarReaderView start is where we are hung up for a long time.

Any ideas?

Was it helpful?

Solution

Your problem might be related to this (check the comments):

iOS7 : UIImageView Takes Forever to Appear

We don't know which commands [self.zBarReaderView start] actually executes, but the documentation for ZBarReaderView says :

This is a barcode reader encapsulted in a UIView.

If it's laying out subview in UIViews, supposedly it's not safe to call "start" in a background thread, and while in iOS6 this worked it doesn't in iOS7 anymore, since the internals have changed.

Try to init the camera in the main thread, and see if it works:

 dispatch_async(dispatch_get_main_queue(), ^{[self.zBarReaderView start];});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top