AVCaptureSession无法在调用beginConfiguration / commitConfiguration之间启动

时间:2013-12-20 11:40:49

标签: ios avfoundation zxing

我正在尝试用 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];

我收到了这个错误:

*由于未捕获的异常'NSGenericException'而终止应用程序,原因:'* AVCaptureSession无法在调用beginConfiguration / commitConfiguration之间启动运行'

2 个答案:

答案 0 :(得分:2)

它可以工作,如果是这样

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.   

答案 1 :(得分:1)

修补程序建议:

进入[ZXCapture start]并查看dispathc_asyn部分的评论:

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

我不会再崩溃了,但是你会在会话需要开始的时候阻止你的主线程 - >修补程序,直到zxing的人提出解决方案。