我正在使用Zxing扫描数据矩阵代码。我从github导入了zxing。当应用程序启动时,只要照相机放置在条形码上,照相机就会反复扫描代码。我想在条形码解码后停止扫描,然后我想要执行任务,然后再次开始扫描。我停止了扫描,但无法启动它。这是我已经做了停止扫描。停止ZxingObjC中的连续扫描
这是我ViewController.m
- (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result {
if (!result) return;
// We got a result. Display information about the result onscreen.
NSString *formatString = [self barcodeFormatToString:result.barcodeFormat];
NSString *display = [NSString stringWithFormat:@"Scanned!\n\nFormat: %@\n\nContents:\n%@", formatString, result.text];
//here i called the stop method
[self.capture stop];
//i want to start scanning again ,so i created this method
[self afterScan];
}
现在,一旦条形码被解码相机停止。现在我想实现这个方法
-(void) afterScan{
// UIAlertVIew " code is decoded "
// store in database
// again start scanning
[self.capture start];
}
问题是相机不能再次启动。是
的启动和停止方法在斑马线如下:
- (void)start {
if (self.hardStop) {
return;
}
if (self.delegate || self.luminanceLayer || self.binaryLayer) {
[self output];
}
if (!self.session.running) {
static int i = 0;
if (++i == -2) {
abort();
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.session startRunning];
});
}
self.running = YES;
}
- (void)stop {
if (!self.running) {
return;
}
if (self.session.running) {
[self.layer removeFromSuperlayer];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.session stopRunning];
//[self.session startRunning];
});
}
self.running = NO;
}
能否请你帮我解决这个问题。
在此先感谢。
我用[_capture stop]停止扫描,我尝试通过[_capture start]启动它,但相机未启动。 [_capture start]启动摄像头是否正确? – 2014-08-28 15:07:29
停止API不工作,最好的方法是使用布尔参数。 – ondermerol 2017-03-09 13:13:53
这个布尔如何停止相机@ondermerol – 2017-09-12 09:03:37