Search code examples
iosobjective-cswiftbarcodeavcapturesession

Capture barcode from front camera iOS


In my app I've to capture a barcode with AVCaptureVideoPreviewLayer and AVCaptureSession, when I use the rear camera all works perfectly and very fast, but when I try to read the same code from the front camera it doesn't work. I tried to mirror the AVCaptureVideoPreviewLayer with the following code videoPreviewLayer.affineTransform = CGAffineTransformMakeScale(-1, 1);, it mirror the image but the device is still unable to detect barcode. There's a way to detect a barcode from the front camera?


Solution

  • There's a way to detect a barcode from the front camera?

    Yes, you can use a third party library to do that. For example ZXingObjC.

    You will need to setup your ZXCapture object like this:

      ZXCapture *capture = [[ZXCapture alloc] init];
      capture.camera = self.capture.front;
      capture.focusMode = AVCaptureFocusModeLocked;