Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一次扫描二维码, 结果会重复返回. #187

Open
lihanxingGitHub opened this issue Mar 14, 2024 · 3 comments
Open

第一次扫描二维码, 结果会重复返回. #187

lihanxingGitHub opened this issue Mar 14, 2024 · 3 comments

Comments

@lihanxingGitHub
Copy link

第一次扫描二维码, 结果会重复返回.
截屏重复返回

@wsrGitHub
Copy link

我也遇到了,有解决方案吗

@MichaelYNWA
Copy link

我也遇到了,怎么解决啊?

@DoctorWiseman
Copy link

识别速度太快,增加上微秒级别的防抖

@interface SGScanCode () 
//增加上一次处理时间戳属性
@property (nonatomic, assign) uint64_t lastProcessedTimestamp;
@end
    
#pragma mark - - AVCaptureMetadataOutputObjectsDelegate 的方法
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
    // 获取当前的 CFAbsoluteTime
    CFAbsoluteTime currentCFTime = CFAbsoluteTimeGetCurrent();

    // 将 CFAbsoluteTime 转换为微秒
    uint64_t microseconds = (uint64_t)(currentCFTime * 1000000);

    // 打印当前时间的微秒级别
    NSLog(@"当前时间的微秒: %llu", microseconds);
    
    // 计算时间差
    uint64_t timeDifference = microseconds - self.lastProcessedTimestamp;
    
    // 设置防抖时间间隔,例如 500 毫秒(500000 微秒)
    uint64_t debounceInterval = 500000;
    
    // 如果时间差大于防抖时间间隔,则处理元数据对象
    if (timeDifference > debounceInterval) {
        //此处编写你的二维码处理逻辑

        self.lastProcessedTimestamp = microseconds; // 更新上一次处理时间戳
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants