Q:

AVcaptureMetadataOutput does not work in ios10

I used the AVCaptureMetadataOutputObjectsDelegate for a barcode scanner and it worked perfect. But since iOS 10 it does not working anymore. I always get a EXC_BAD_ACCESS error when I open the barcodescanner with it´s button. The error occurs when I add an output to the session.
Can someone help me please? I really tried everything and it drives me crazy.

A:

Here's my Objective-C, which is working fine under iOS 10. IIRC I think I had trouble if the vars were only local to the method. Ensure all your vars are properties.
- (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
    }
}

