0

I'm trying to do an AVCaptureSession on the front camera to read a PDF417 barcode, but it refuses to read the same barcodes on the front camera that it will read no problem on the back. Is there a setting I'm missing or does it have to do with the front camera appearing "mirrored?"

I tried the same thing with a QR code and it works no problem on both the front and back cameras.

_session = [[AVCaptureSession alloc] init];

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for( AVCaptureDevice *device in videoDevices )
{
    if( device.position == AVCaptureDevicePositionFront )
    {
        _device = device;
        break;
    }
}

//  couldn't find one on the front, so just get the default video device.
if( ! _device)
{
    _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}

// _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;

if( _device.isAutoFocusRangeRestrictionSupported )
{
    if( [_device lockForConfiguration:&error] )
    {
        [_device setAutoFocusRangeRestriction:AVCaptureAutoFocusRangeRestrictionNear];
        [_device unlockForConfiguration];
    }
}

_input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
if (_input) {
    [_session addInput:_input];
} else {
    NSLog(@"Error: %@", error);
}

_output = [[AVCaptureMetadataOutput alloc] init];
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:_output];

// _output.metadataObjectTypes = [_output availableMetadataObjectTypes]; _output.metadataObjectTypes = @[AVMetadataObjectTypePDF417Code ];

_prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
_prevLayer.frame = self.view.bounds;
_prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self updatePreviewLayerForOrientation:[[UIApplication sharedApplication] statusBarOrientation] ];

[self.view.layer addSublayer:_prevLayer];

[_session startRunning];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mikey A. Leonetti
  • 2,834
  • 3
  • 22
  • 36

0 Answers0