ios - AVcaptureMetadataOutput 在 ios10 中不起作用

标签 ios objective-c exc-bad-access

我将 AVCaptureMetadataOutputObjectsDelegate 用于条形码扫描仪,效果非常好。但自 iOS 10 以来,它不再工作了。当我用它的按钮打开 barcodescanner 时,我总是收到一个 EXC_BAD_ACCESS 错误。当我向 session 添加输出时发生错误。

有人可以帮帮我吗?我真的尝试了一切,这让我发疯。

最佳答案

这是我的 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
    }
}

关于ios - AVcaptureMetadataOutput 在 ios10 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39725995/

相关文章:

ios - UIPageViewController 与 TableView

ios - 将字符串制作成 SKNode

iphone - 子类化 UIWindow

objective-c - 参数的可变参数方法 : Check, 是一个 typedef ed block

objective-c - 如何在不关闭标签的情况下解析XML数据Objective-C

iOS 6.1.3 EXC_BAD_ACCESS KERN_INVALID_ADDRESS

ios - 设置 <UITouch>?没有名为 Generator 的成员

ios - CF网络崩溃

ios - 将对象添加到NSMutableArray时抛出EXC_BAD_ACCESS

ios - Objective C,在堆栈跟踪中不涉及我的应用程序时处理崩溃报告