我使用AVCaptureMetadataOutputObjectsDelegate
作为条形码扫描器,它的工作非常完美。但是从iOS 10开始,它不再工作。当我用它的按钮打开barcodescanner
时,我总是得到一个EXC_BAD_ACCESS错误。将输出添加到会话时发生错误。AVcaptureMetadataOutput在ios10中不起作用
有人可以帮我吗?我真的尝试了一切,这让我疯狂。
我使用AVCaptureMetadataOutputObjectsDelegate
作为条形码扫描器,它的工作非常完美。但是从iOS 10开始,它不再工作。当我用它的按钮打开barcodescanner
时,我总是得到一个EXC_BAD_ACCESS错误。将输出添加到会话时发生错误。AVcaptureMetadataOutput在ios10中不起作用
有人可以帮我吗?我真的尝试了一切,这让我疯狂。
这里是我的Objective-C,这是在iOS的10 IIRC工作正常,我想我有麻烦,如果瓦尔只是局部性的方法。确保你的所有变量都是属性。
- (void)initialiseVideoSession {
_session = [[AVCaptureSession alloc] init];
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
_input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
if (_input) {
[_session addInput:_input];
_output = [[AVCaptureMetadataOutput alloc] init];
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:_output];
_output.metadataObjectTypes = [_output availableMetadataObjectTypes];
_prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
_prevLayer.frame = self.view.bounds;
_prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer:_prevLayer];
[_session startRunning];
} else {
// Error
}
}
谢谢队友。这是完美的。 –
这是我现在的作品。
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
// Get the first object from the metadataObjects array.
if let barcodeData = metadataObjects.first {
// Turn it into machine readable code
let barcodeReadable = barcodeData as? AVMetadataMachineReadableCodeObject;
if let readableCode = barcodeReadable {
// Send the barcode as a string to barcodeDetected()
barcodeDetected(readableCode.stringValue);
}
// Vibrate the device to give the user some feedback.
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
// Avoid a very buzzy device.
session.stopRunning()
}
}
添加您的代码!提供更多细节! –