Ios 获取条形码后,摄像头不会关闭
我正在使用这类Ios 获取条形码后,摄像头不会关闭,ios,objective-c,avfoundation,barcode,Ios,Objective C,Avfoundation,Barcode,我正在使用这类avfoundationframework扫描条形码 AVCaptureSession *_session; AVCaptureDevice *_device; AVCaptureDeviceInput *_input; AVCaptureMetadataOutput *_output; AVCaptureVideoPreviewLayer *_prevLayer; 我的问题是,当我成功获取条形码时,我的相机视图没有被关闭。他保持打开状态,你能告诉我当我获取条形码时,我的相机应该
avfoundationframework
扫描条形码
AVCaptureSession *_session;
AVCaptureDevice *_device;
AVCaptureDeviceInput *_input;
AVCaptureMetadataOutput *_output;
AVCaptureVideoPreviewLayer *_prevLayer;
我的问题是,当我成功获取条形码时,我的相机视图没有被关闭。他保持打开状态,你能告诉我当我获取条形码时,我的相机应该被关闭,这是我获取条形码的代码
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)
metadataObjects fromConnection:(AVCaptureConnection *)connection
{
CGRect highlightViewRect = CGRectZero;
AVMetadataMachineReadableCodeObject *barCodeObject;
NSString *detectionString = nil;
NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code,
AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code,
AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode];
for (AVMetadataObject *metadata in metadataObjects) {
for (NSString *type in barCodeTypes) {
if ([metadata.type isEqualToString:type])
{
barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata];
highlightViewRect = barCodeObject.bounds;
detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
break;
}
}
if (detectionString != nil)
{
NSLog(@"%@",detectionString);
txt_cardSerialNumber.text = detectionString;
break;
}
else
_label.text = @"(none)";
}
_highlightView.frame = highlightViewRect;
}