4

Hi I am trying to develop app for 1D and 2D Barcode scanning, it works well in iOS 9.3 and Xcode 7.3 but when I am trying to run same application in iOS 10 and Xcode 8.2 application get crashed on below line. Please help on it.

[_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];

}
Evgeny Karkan
  • 8,782
  • 2
  • 32
  • 38
Yogesh Raut
  • 180
  • 11

3 Answers3

2

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];
Community
  • 1
  • 1
Yogesh Raut
  • 180
  • 11
0

Did you add Camera Usage Description to your plist file? If no, take a look on this blog.

Oleshko
  • 2,923
  • 4
  • 17
  • 25
  • I have added in plist file, but result is same. – Yogesh Raut Mar 10 '17 at 12:21
  • Your app should ask user permission to access the camera. If not, try to rebuild / reinstall the app. But if it did, then update your question with crash log, please. – dive Mar 10 '17 at 12:23
  • It ask for permission. Following is Crash log. First Error printed on Log 1) Error: Error Domain=AVFoundationErrorDomain Code=-11814 "Cannot Record" UserInfo={NSLocalizedRecoverySuggestion=Try recording again., NSLocalizedDescription=Cannot Record} 2nd Error Thread EXC_BAD_ACCESS – Yogesh Raut Mar 10 '17 at 13:02
  • @YogeshRaut Sorry for the dumb question, but - are you getting this on a real device, right? Or maybe iOS Simulator... – Evgeny Karkan Mar 10 '17 at 13:41
  • On both Simulator and on device also. – Yogesh Raut Mar 11 '17 at 08:17
0

iOS 10 requires more privacy with the usage of hardware input sources.
Your app works with a camera, and you need to provide additional explanation of why it needs a camera.

So, go to your Info.plist file and add an additional key-value pair dictionary there.
For key choose - Privacy Camera Usage Description
For value add some string like next - App needs a camera to make amazing photos, scan barcodes, etc...

To be sure if everything is Ok, go to Settings iOS app and check there for camera toggle switched to On for you application.

Evgeny Karkan
  • 8,782
  • 2
  • 32
  • 38