我用zxing扫描条形码。但是相机会快速扫描,因此我的方法会因结果而过载。如何减慢速度或创建延迟扫描条形码?
这是我的结果方法:
- (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];
[self.decodedLabel performSelectorOnMainThread:@selector(setText:) withObject:display waitUntilDone:YES];
// Vibrate
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
答案 0 :(得分:2)
您可以录制NSTimeInterval
并拒绝下一个' x'的所有结果。秒。每半秒最多检测一次的例子:
- (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result {
if ([[NSDate date] timeIntervalSince1970] < _nextUpdateTime) {
return;
}
_nextUpdateTime = [[NSDate date] timeIntervalSince1970] + 0.5;
// remainder of function.
}
答案 1 :(得分:1)
我建议你使用睡眠功能。尝试使用sleep(timeInSeconds),因此它会使扫描器延迟你输入的秒数。