2011-11-23 3 views
0

現在のコード説明: iPhoneアプリケーションにはZBar SDKが組み込まれており、バーコードをスキャンします。最初のバーコードが返され、私はsymbol.data(バーコード情報)をupdateTotalに送ります。 updateTotalでは、スキャンしたバーコードが私が探しているもの(matchBarcodeと宣言されているもの)かどうかを確認します。この場合、バーコードが実際に探しているものであれば、バーコードがスキャンしていると言っています。そうでない場合は、正しいバーコードではないという警告が表示されます。Zbarスキャナsymbol.data比較iPhoneスキャナ

問題:どのバーコードがスキャンされても、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]; 
     } 
    } 

答えて

0

のNSStringの使用isEqualToString方法。

if([barcode isEqualToString: matchBarcode]){} 
+0

です。ありがとうございました。 – morcutt