Using the below code, the issue is I have two buttons and two textfields but I am getting the qrcode value using single method. How can i use it for two textfields
- (IBAction) keyScanButtonTapped
{
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 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
deviceKey.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 dismissModalViewControllerAnimated: YES];
}
Do you simply want to connect two different buttons to this same function? That is no problem just go into interface builder and connect both buttons to this method. You can see this question on how to connect buttons in interface builder
How can I connect "File's Owner" with a button in a Toolbar?
when the callback function is called you can identify which button called the function in such a manner
-(void)buttonPressed:(id)sender{
//find out which button was pressed
UIButton * pressed = (UIButton*) sender;
NSInteger tag = pressed.tag;
}
the tags are defined in the interface builder, just make sure that they are different for the two buttons and you are good to go.
Related
I am facing one little issue using ZBarCode reader in iPhone, i have implemented ZBarCode and it is working successfully, however some times it usually add an integer value 0 at the beginning after scanning bar code and due to this some times result are not coming accurately, please let me know if i am doing some thing wrong.
For Bar Code and QR code scanning i have created full detailed tutorial and posted sample code. and it gives me every time perfect info.
How to use Barcode Scanner (BR and QR) in iPhone Tutorial (using ZBar)
Here is the core logic.
startScanning method body this way
- (IBAction)startScanning:(id)sender {
NSLog(#"Scanning..");
resultTextView.text = #"Scanning..";
ZBarReaderViewController *codeReader = [ZBarReaderViewController new];
codeReader.readerDelegate=self;
codeReader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = codeReader.scanner;
[scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
[self presentViewController:codeReader animated:YES completion:nil];
}
Implement ZBar's Delegate method
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// just grab the first barcode
break;
// showing the result on textview
resultTextView.text = symbol.data;
resultImageView.image = [info objectForKey: UIImagePickerControllerOriginalImage];
// dismiss the controller
[reader dismissViewControllerAnimated:YES completion:nil];
}
Could you post code you are using? Maybe you are using old referecne? Make sure all references are pointing nil value before parsing new scanned data.
I am using ZBar iPhone SDK in one of my projects (iOS SDK 5.1 ,XCode 4.4.1 and device running iOS 5.5.1). I am using the embedded scanner from the examples provided in the SDk itself.
Now the issue which I am facing is that I successfully scan a bar code and move to another view controller ( using navigation controller). When I come back (pop the second view controller) the scanner i.e the ZBarReaderView doesn't scan the subsequent bar codes , infact the overlay shows a blur image of the scanned barcode and is never able to scan it properly.
This is what all I have implemented . In BarScannerViewController.h I have declared
ZBarReaderView* readerView;
with property
#property (nonatomic , retain) IBOutlet UIImageView* imgvScannedBarCode;
Now this is connected to one of the views in xib.
Finally I use set up the required methods as follows -
- (void)viewDidLoad {
[super viewDidLoad];
// the delegate receives decode results
readerView.readerDelegate = self;
[readerView start];
}
- (void) viewDidAppear: (BOOL) animated {
// run the reader when the view is visible
[activityIndicatorScanning startAnimating];
[readerView start];
}
- (void) viewWillDisappear: (BOOL) animated {
[activityIndicatorScanning stopAnimating];
[readerView stop];
}
With all this set up when I scan any bar code say EAN123 for the first time I get the call back in
- (void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
// do something useful with results
ZBarSymbol *symbol = nil;
for(symbol in syms) {
barCodeFound = YES;
break;
}
// EXAMPLE: do something useful with the barcode data
NSLog(#"%#",symbol.data);
}
but on subsequent runs (After I push a view and come back on this screen again) I get blurred view.
Am I missing something here ? Any help/Suggestion/Comments would be helpful.
Here's the code that I use to start (and endlessly restart) the scanner. Interestingly, I note that I never stop the scan, but it works very reliably.
- (void) startScan
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentViewController:reader animated:YES completion:nil]; // Modal
[reader release];
}
I could solve the Blur issue by reconfiguring the SDK in my project. I followed the embedded scanner example as provided on ZBarSDk. I guess I might have missed some essential settings while configuring it earlier.
I have an application in which I have a UIView (Zbarsdk reader view) in my xib. When a button is tapped, that view should be loaded. But actually when the button is tapped, the previous view is loading at first (from which I came to my view). But after running once then again running then the correct view is loading? (From login I came to home. In home I have one button to load one view that is separate in my xib, but when running first it is loading the login screen again. But without deleting that build when u run again that code in simulator is loading that correct view). Does anybody know why?
- (IBAction) tappressed
{
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
[reader willRotateToInterfaceOrientation:UIInterfaceOrientationPortrait duration:0];
//[self.readerView willRotateToInterfaceOrientation:orient duration:0];
//reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationLandscapeRight);
// [reader shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
//reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationLandscapeLeft);
reader.sourceType=UIImagePickerControllerSourceTypeCamera;
// UIImageView *overlayImage=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"overlaygraphic.png"]];
//overlayImage.bounds=CGRectMake(50, 75, 320-100, 480-150);
reader.cameraOverlayView=cameraOverlay;
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 presentModalViewController:reader animated:YES];
// [self.view addSubview:reader.view];
[reader release];
}
i've got a ZBarReaderView created from storyboard with 216x20 px which is shown as roughly 230x50 px because ZBarReaderView doesn't take it's size too serious...
It all works very well, however it behaves really strange when I call start on that readerView. It starts the cam but then in maybe half a second the readerView zooms a bit and the camera picture inside the readerView moves down and then up again.
It's not terrible but it look kinda bad. Anyone got any ideas what might be causing this and how to solve it? Maybe the sdk has some sort of hidden callback for the readiness of the scanner, i could hide it until the scanner says it's ready and then show the scanner like .5 seconds later...
barcodeReader is the iboutlet to the ZBarReaderView and scannerLoading is an iboutlet to a uiactivityindicatorview which is animating until the scanner is loaded.
These are the only settings which are changed from default, except the frame which is set in the storyboard of course.
[barcodeReader setReaderDelegate:self];
[barcodeReader setAllowsPinchZoom:false];
[barcodeReader start];
/* this works because [barcodeReader start] blocks ui updates until the scanner
is running, i know it's not a good solution but since there doesn't seem to
be a callback or delegate method like scannerDidStart or something it seems
to be the only way... */
[scannerLoading stopAnimating];
Thanks for your help!
I just posted an answer to a retaliated question:
ZBarReadview with custom size from StoryBoard,but when it's called,it's size is not I set
Maybe the answer also solves your problem.
In short:
When using Interface Builder or Storyboard to create a view and assign the ZBarReaderView to it, you have to check "Clip Subviews" in the properties for the camera image to keep the size of the view.
Just add another view to make it as cameraoverlayview with an image view having the image which is having required part of it as transparent.then in the button action `
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.sourceType=UIImagePickerControllerSourceTypeCamera;
//reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
reader.cameraOverlayView=cameraOverlay;
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ])
{
reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
ZBarImageScanner *scanner = reader.scanner;
reader.wantsFullScreenLayout = YES;
// 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];
reader.showsZBarControls = NO;
// present and release the controller
[self presentModalViewController:reader animated:YES];
//[appdel.navigationController pushViewController:reader animated:YES];
//[reader.view addSubview:collect];
[reader release];add this and then also add
`- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
[self rewards:symbol.data];
}
`
as a method .hope this will solve your issue
I am working on an application that scans the QR codes.When the scan button is clicked,it goes to the generic full page camera view.But i need to customize that page so that a logo must be shown at the bottom and a button at the top.the scanning area should be in between these two.How can i implement the?anyone have answer?the code i am using is given below
- (IBAction) scanButtonTapped
{
// 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;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
[reader release];
}
You can set property cameraOverlayView of ZBarReaderViewController. Some docs is here.
ZBarReaderViewController* reader = [[ZBarReaderViewController alloc] init];
reader.cameraOverlayView = yourCustomView;
To change tabBar you can add your subview.
You can access it using this:
UIView* subView1 = [reader.view.subviews objectAtIndex:2];
UIView* tabBar = [subView1.subviews objectAtIndex:0];
Now you can customize tabBar in the way you like.