Scan barcode with AVFoundation AVCaptureMetadataOutput

Hi Team,

I'm using AVFoundation AVCaptureMetadataOutput for scan barcode

Here is my code

- (BOOL)startReading {

NSError *error;

AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];

if (!input) {

NSLog(@"%@", [error localizedDescription]);

return NO;

}


m_pCaptureSession = [[AVCaptureSession alloc] init];

[m_pCaptureSession addInput:input];

m_pCaptureSession.sessionPreset = AVCaptureSessionPresetHigh;


AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];

[m_pCaptureSession addOutput:captureMetadataOutput];


//captureMetadataOutput.metadataObjectTypes = [captureMetadataOutput availableMetadataObjectTypes];

captureMetadataOutput.metadataObjectTypes = [[NSArray alloc] initWithObjects:AVMetadataObjectTypePDF417Code, nil];

[captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];


//AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:m_pCaptureSession];

m_pPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:m_pCaptureSession];

[m_pPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

[m_pPreviewLayer setFrame:m_pLayoutPreview.layer.bounds];

[self->m_pLayoutPreview.layer addSublayer:m_pPreviewLayer];


[self->m_pLayoutPreview setHidden:NO];

[self->m_pLayoutContent setHidden:YES];

[m_pCaptureSession startRunning];

return YES;

}


- (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection

{

for (AVMetadataObject *barcodeMetadata in metadataObjects) {

if ([barcodeMetadata.type isEqualToString:AVMetadataObjectTypePDF417Code])

{

//AVMetadataMachineReadableCodeObject *barcodeObject = (AVMetadataMachineReadableCodeObject *)[m_pPreviewLayer transformedMetadataObjectForMetadataObject:barcodeMetadata];

AVMetadataMachineReadableCodeObject *barcodeObject = metadataObjects[0];

m_sDataScanLincenseNumber = [barcodeObject stringValue];

[self performSelectorOnMainThread:@selector(fillData) withObject:nil waitUntilDone:NO];

return;

}

}

}


It's work good.

But it's not work with this code https://imge.to/i/vJLJdj

However, my android app can detect data from this barcode

Please tell me my problem is what? and how to relolve it

Thanks.