【问题标题】:Zbar Scanner symbol.data comparison iPhone ScannerZbar 扫描仪 symbol.data 比较 iPhone 扫描仪
【发布时间】:2011-11-23 00:14:42
【问题描述】:

当前代码说明: iPhone 应用程序结合了 ZBar SDK 来扫描条码。返回第一个条形码,我将 symbol.data(条形码信息)发送到 updateTotal。在 updateTotal 中,我检查扫描的条码是否是我正在寻找的条码(声明为 matchBarcode。)在这种情况下,如果条码确实是我正在寻找的条码,它会显示一条警报扫描的条形码是这样说的。如果不是,它会显示一条警报,说明它不是正确的条形码。

问题:无论扫描什么条码,返回的都是不等于matchBarcode的字符串。

我的想法:我认为这与条形码 (symbol.data) 不是 NSString 有关,但在 ZBar SDK 中它声明它是。我已经为此工作了一段时间,但无法弄清楚。我敢肯定这是一个愚蠢的错误。请帮忙。

当前代码:

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;

    [self updateTotal:symbol.data];

    NSLog(@"%@", symbol.data);
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissModalViewControllerAnimated: YES];
}




    -(void)updateTotal:(NSString *)barcode
    {
        // Barcode I am looking for
        NSString *matchBarcode = @"FoundBarcode";
        // Barcode Comparison
        if (barcode == matchBarcode) {
            // Alert stating this IS the barcode you are looking for
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Barcode" message:barcode delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            [alert release];
        } else {
            // Alert stating this is not the barcode you are looking for
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Barcode" message:barcode delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            [alert release];
        }
    }

【问题讨论】:

    标签: iphone objective-c barcode barcode-scanner


    【解决方案1】:

    使用 NSString 的 isEqualToString 方法。

    if( [barcode isEqualToString: matchBarcode]){}
    

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      相关资源
      最近更新 更多