gpt4 book ai didi

ios - Zbar sdk 扫描仪无法正常工作

转载 作者:行者123 更新时间:2023-12-01 19:13:00 26 4
gpt4 key购买 nike

在我的应用程序中,我集成了 Zbar SDK 扫描器,虽然扫描通常可以正常工作,但我的情况有时是 didfinishpickingmediawithInfo: 委托(delegate)方法触发两次。这是我在单音类中的代码。

-(void)scanProductBarCode
{

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;


if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
reader.supportedOrientationsMask = ZBarOrientationMaskLandscape;
else
reader.supportedOrientationsMask = ZBarOrientationMaskPortrait;

ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_UPCA config: ZBAR_CFG_ENABLE to: 1];
[scanner setSymbology: ZBAR_CODE39 config: ZBAR_CFG_ADD_CHECK to: 0];


}

#pragma mark - Scanner delegate methods

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;

barCodeString = [[NSString alloc] initWithString:symbol.data];

if(self.delegate)
[self.delegate getBarcodeString:barCodeString];

[reader dismissModalViewControllerAnimated:YES];


}

看这个屏幕截图:

enter image description here

在后台,扫描仪在两次发生的情况下仍然像这样运行..

最佳答案

我遇到了同样的问题。我添加了 BOOL我的类的实例变量 _processing .然后我这样做了:

- (void)imagePickerController:(UIImagePickerController*)reader didFinishPickingMediaWithInfo:(NSDictionary*)info
{
if (_processing) return;

id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results) {
_processing = YES;
barCodeString = symbol.data;

if(self.delegate) {
[self.delegate getBarcodeString:barCodeString];
}

break;
}

[reader dismissModalViewControllerAnimated:YES];
}

这确保只处理第一个调用。您可能需要重置 _processing如果您打算多次重用 View Controller 。

关于ios - Zbar sdk 扫描仪无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15152050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com