从前置摄像头捕获条码 iOS

Capture barcode from front camera iOS

在我的应用程序中,我必须使用 AVCaptureVideoPreviewLayerAVCaptureSession 捕获条形码,当我使用后置摄像头时,一切都非常完美且速度非常快,但是当我尝试读取相同的代码时从前置摄像头它不起作用。我尝试使用以下代码 videoPreviewLayer.affineTransform = CGAffineTransformMakeScale(-1, 1); 来镜像 AVCaptureVideoPreviewLayer,它镜像了图像,但设备仍然无法检测到条形码。有办法检测前置摄像头的条形码吗?

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

是的,您可以使用第三方库来做到这一点。例如 ZXingObjC.

您需要像这样设置 ZXCapture 对象:

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