How to get price of Barcode from zBar sdk?

536 Views Asked by At

I have implemented ZBar sdk on my project. The code work perfectly. But every time it scan the code it will give me a number not the barcode price. And My client ask me to show price on label not code.

So how can I show code on label that is my question?

Please check my code:

. h file
@property (nonatomic, retain)  UIImageView *resultImage;
@property (nonatomic, retain)  UITextView *resultText;


.m file

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColor grayColor];

resultImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 300, 250)];
resultImage.backgroundColor = [UIColor clearColor];
[self.view addSubview:resultImage];



resultText=[[UITextView alloc]initWithFrame:CGRectMake(10, 380, 300, 100)];
resultText.backgroundColor=[UIColor redColor];
resultText.text=@"";
resultText.textColor = [UIColor whiteColor];
resultText.delegate =self;
resultText.textAlignment=NSTextAlignmentCenter;
resultText.userInteractionEnabled = NO;
resultText.font=[UIFont fontWithName:@"Helvetica" size:12];
[self.view addSubview:resultText];
//[txtGap release];




UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.backgroundColor = [UIColor whiteColor];
[button addTarget:self action:@selector(scanButtonTapped)forControlEvents:UIControlEventTouchDown];
button.titleLabel.font=[UIFont systemFontOfSize:11];
[button setTitle:@"Get Bar Code" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 500, 120, 35);
[self.view addSubview:button];
}



- (void) scanButtonTapped
{
NSLog(@"TBD: scan barcode here...");

// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here

// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];

// present and release the controller

[self presentViewController:reader animated:NO completion:nil];



 //  [self presentModalViewController: reader animated: YES];
 [reader release];


 }


- (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;

// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;

// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];

// ADD: dismiss the controller (NB dismiss from the *reader*!)

[reader dismissViewControllerAnimated:YES completion:nil];


// [reader dismissModalViewControllerAnimated: YES];
}
2

There are 2 best solutions below

0
Retro On

Bar code is mostly give the information of product not the price so its up to you how you can return the price of the product, best way which i can guess you must have a table at server side to compare with your bar code and return price of the product which could be show on label

0
bs7 On

ZBar will only give you the EAN/UPC code of the bar code (13 numbers), NOT the price. You have to ask a web service (for example) with the given code to retrieve the price.

As far as I know, there is no way that scanning the bar code gives you the price without associating the code to a price (in your app, or by performing a HTTP request)

Sorry.