您好我正在尝试开发1D和2D条码扫描的应用程序,它在iOS 9.3和Xcode 7.3中运行良好,但是当我尝试在iOS 10和Xcode 8.2应用程序中运行相同的应用程序时,会在下面的行中崩溃。 请帮帮忙。
[_ session addOutput:_output];
-(void)setupCaptureSession{
_session = [[AVCaptureSession alloc] init];
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
_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]; // here Application get crashed.
_output.metadataObjectTypes = [_output availableMetadataObjectTypes];
_prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
_prevLayer.frame = _previewView.bounds;
_prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[_previewView.layer addSublayer:_prevLayer];
//[self.view];
//[_session startRunning];
[_previewView bringSubviewToFront:_highlightView];
}
答案 0 :(得分:1)
Hi I have just commented, following code of line
[_ previewView.layer addSublayer:_prevLayer];
and added below code of line in my app and app works without error.
[_ previewView.layer insertSublayer:_prevLayer atIndex:0];
答案 1 :(得分:0)
您是否在plist文件中添加了相机使用说明?如果不是,请查看this博客。
答案 2 :(得分:0)
iOS 10
需要更多隐私
您的应用程序适用于相机,您需要提供有关其需要相机的原因的其他说明。
因此,请转到您的Info.plist
文件,然后在其中添加其他key-value
字对字典
关键选择 - Privacy Camera Usage Description
对于值,请添加一些字符串,例如next App needs a camera to make amazing photos, scan barcodes, etc...
要确定一切正常,请转到Settings
iOS应用并检查相机切换是否为您的应用程序切换到On
。