Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureSession can't startRunning between calls to beginConfiguration / commitConfiguration

I'm trying to read QR code with Zxing :

self.capture = [[ZXCapture alloc] init];
self.capture.rotation = 90.0f;

// Use the back camera
self.capture.delegate = self;
self.capture.camera = self.capture.back;

self.capture.layer.frame = self.view.bounds;
[self.view.layer addSublayer:self.capture.layer];

I'm getting this error :

* Terminating app due to uncaught exception 'NSGenericException', reason: '* AVCaptureSession can't startRunning between calls to beginConfiguration / commitConfiguration'

like image 617
Nabil El Avatar asked Apr 26 '26 12:04

Nabil El


2 Answers

It can work, if so

self.capture = [[ZXCapture alloc] init];
self.capture.rotation = 90.0f;

// Use the back camera

self.capture.camera = self.capture.back;

self.capture.layer.frame = self.view.bounds;
[self.view.layer addSublayer:self.capture.layer];

self.capture.delegate = self; // this must be last.   
like image 61
shilei365 Avatar answered Apr 29 '26 03:04

shilei365


Hotfix Suggestion:

Go into [ZXCapture start] and look comment the dispathc_asyn part:

// NSLog(@"start running");
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      [self.session startRunning];
//    });

I won't crash anymore but you will then block your main thread for the time the session needs to start -> Hotfix till the guys from zxing come up with a solution.

like image 25
Muscovado Avatar answered Apr 29 '26 03:04

Muscovado