5

I'm working on an app that the user can select if he wants to scan a barcode or take a picture of something. For taking a picture I'm using the UIImagePickerController as usual. For scanning barcode I'm using the ZbarSDK 1.2 ZBarReaderViewController.

When taking a picture everything works perfect. When scanning a barcode: If you start the app and scan a barcode before taking a picture, it's also works perfect.

But is you take a picture, and then go back and try to scan a barcode, the camera loses the auto-focus and it's just impossible to scan a barcode.

To summarize:
Start -> Scan -> Auto focus working
Start -> Take Photo -> Back -> Scan -> Auto focus not working

This is how I initialize the barcode scanner:

-(ZBarReaderViewController *) barcodeScanner
{
    if (nil == _barcodeScanner)
    {
        _barcodeScanner = [ZBarReaderViewController new];
        _barcodeScanner.readerDelegate = self;
        _barcodeScanner.cameraMode = ZBarReaderControllerCameraModeSampling;
        _barcodeScanner.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    return _barcodeScanner;
}

Any ideas?

Avi Shukron
  • 6,088
  • 8
  • 50
  • 84

3 Answers3

4

Before loading up ZBarReaderViewController make sure you release UIImagePickerController, and before you load up UIImagePickerController make sure you release ZBarReaderViewController.

It took me days to figure out why i kept losing the ability to focus, and turns out that i wasn't releasing things. For others stumbling onto this answer... You can only have 1 AVCaptureSession at a time otherwise things get screwy and you lose the ability to focus. ZBarReaderViewController uses AVCaptureSession so make sure you release it before you initialize a new AVCaptureSession.

AlBeebe
  • 8,101
  • 3
  • 51
  • 65
1

We were facing same issue with Zbar, we solved it by putting a 2 sec delay before dismissing model view.

0

I would look deeper into your implementation of taking picture. Try to check if you close the resource correctly when done taking the photo. I don't think zBar implementation got anything to do with it...

Oded Regev
  • 4,065
  • 2
  • 38
  • 50
  • The point is - I have no implementation of "Taking picture"... I'm just initializing the UIImagePickerController, present it modally and get the callback when the picture was taken. I'm not doing any fancy stuff myself. – Avi Shukron Jan 01 '12 at 12:17