QR code integration - iphone

I am facing some problem after integrating ZBar framework for scanning QRCodeRead on my apps. My client wants, QRCode Scanner will be in a fixed frame and must not be a PresentModalView. So I write code for fixed frame QRCode Scanner and added the reader.view on self.view, but it not working as presentModalViewController:reader. I don't know what is going wrong. I am not able to solve this issue. I have provided my code below and Sorry for my bad English.
This Code is working...
- (IBAction) scanButtonTapped
{
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];
}
But this Code is not working...
- (IBAction) scanButtonTapped
{
// Create new reader
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
[reader.scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
reader.showsCameraControls = NO;
reader.showsZBarControls = NO;
[reader setWantsFullScreenLayout:NO];
reader.showsHelpOnFail = NO;
reader.showsZBarControls = NO;
[reader.view setFrame:CGRectMake(20, 134, 280, 202)];
[self.view addSubview:reader.view];
[reader release];
}
Please help me and provide a solution.Thanks in advance.

Related

NSNSInternalInconsistencyException, Missing outlet IOS7

Okay, I am stumped... all the answers related missing outlets point to making sure that the outlet is connected. I have made sure that it is. You can see it in the screenshots below. The problem is that the code runs in IOS5.0. So this is definitely some compatibility related issue. I have also tried what was suggested in the two answers. But that doesn't help.
Here is the code that invokes the xib. Any clues? Thank you for helping.
- (id) initWithModuleDataDict:(id)dataObject andStepNumber:(int)stepNumber
{
if ((self = [super initWithNibName:#"PhoneContent" bundle:nil])) {
self.moduleData = (NSDictionary *)dataObject;
self.module = [self.moduleData objectForKey:kModuleClassKey];
numberOfSteps = [[self.module steps] count];
self.doShowMeasurementViews = self.module.doShowMeasurementViews;
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
// view controllers are created lazily in the loadScrollViewWithPage: method...
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < numberOfSteps; i++)
{
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
// CGRect fullScreenRect = [[UIScreen mainScreen] applicationFrame];
CGRect fullScreenRect = CGRectMake(0, 0, 320, 372);
UIScrollView *theScrollView = [[UIScrollView alloc] initWithFrame:fullScreenRect];
self.scrollView = theScrollView;
[theScrollView release];
CGRect bottomRect = CGRectMake(0, 410, 320, 20);
UIPageControl *thePageControl = [[UIPageControl alloc] initWithFrame:bottomRect];
thePageControl.center = CGPointMake(160.0, 400.0);
self.pageControl = thePageControl;
[thePageControl release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * numberOfSteps, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.decelerationRate = UIScrollViewDecelerationRateFast; //shp
pageControl.numberOfPages = numberOfSteps;
pageControl.currentPage = stepNumber;
// Create the transition sound
// Create the url for the source audio file (URLForResource:withExtension: method is new in 4.0)
NSURL *purrSound = [[NSBundle mainBundle]URLForResource:#"purr"
withExtension:#"aiff"];
// Store the url as a CFURLRef instance
self.soundFileURLRef = (CFURLRef)[purrSound retain];
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
[controllers release];
}
return self;
}
I have had mixed experiences porting and upgrading old xibs to the new Xcode.
What I have done in these instances is just make a new xib file and copy and paste the controls over from the old. Then I re-assign the superclass and remap the delegates.
I wish I had a better solution, but this has worked for me.
Also, if you were not using AutoLayout in the previous XCode project, keep an eye out for that in Xcode 5 its a little different.
Please add this logic in your code.
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
And read this doc carefully.

How to add a UIview above the current view controllers view?

I have an Ipad application in which i am trying to do some barcode reading processes.when i am pressing a button in the home page i am presenting the barcode reading viewcontrollers view like this`
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.view addSubview:back];
[back addTarget:self action:#selector(backpressed:) forControlEvents:UIControlEventTouchUpInside];
[reader.view addSubview:scan];
[scan addTarget:self action:#selector(getpressed:) forControlEvents:UIControlEventTouchUpInside];
[reader release];
and when i am pressing the scan button added to the reader view i need to add another view.for that i am doing -(IBAction)getpressed:(id)sender{[self.view addSubview:newview] }.but it is not added to the view.can anybody help me to achieve this?
`
you need to overlay to your zbar view and add that button overlay view:
//set the frame according to your requirement
aOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,480.0)];
aOverlay.backgroundColor = [UIColor clearColor];
UIButton *aBtnscan = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aBtnscan setFrame:CGRectMake(115, 435, 80, 45)];
[aBtnscan addTarget:self action:#selector(getpressed:)forControlEvents:UIControlEventTouchUpInside];
[aOverlay addSubview:aBtnscan];
reader.cameraOverlayView = aOverlay;
// You code

Rectangle bringing on camera in ZBar scanner?

How can we bring rectangle on camera for barcode scanning like red laser with scanningound? is there any built in property?I tried following:
reader.readerView.tracksSymbols = YES;
reader.readerView.trackingColor = [UIColor redColor];
[reader setShowsZBarControls:NO];
reader.readerView.tracksSymbols = TRUE;
scanner.accessibilityFrame = CGRectMake(100, 100, 200, 300);
Add the rectange as an overlay on your camera view.Here is the code:
- (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;
reader.showsZBarControls = NO;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
reader.cameraOverlayView = [self CommomOverlay];
[reader release];
}
-(UIView*)CommomOverlay{
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(70,160,203,180)];
[FrameImg setImage:[UIImage imageNamed:#"overlaygraphic.png"]];
[view addSubview:FrameImg];
return view;
}
hope this will help you..:)
Did you try
reader.cameraOverlayView = overLayView;
?? i.e cameraOverlayView property of UIImagePickerController.
There you can set what ever you want. Hope this is what you want.

trying to show a new screen after image is scanned

I am running into an issue that seems so simplistic, is frustrating. I am using the zbar library to play around with scanning qr-codes. Here is my code:
- (IBAction)scanButtonTapped:(id)sender {
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.showsZBarControls = NO;
UIButton *overlay = [UIButton buttonWithType:UIButtonTypeCustom];
overlay.frame = CGRectMake(0, 0, 320, 480);
[overlay setImage:[UIImage imageNamed:#"CameraCover.png"] forState:UIControlStateNormal];
reader.cameraOverlayView = overlay;
overlay.userInteractionEnabled = YES;
[overlay addTarget:self action:#selector(beginScanning:) forControlEvents:UIControlEventTouchUpInside];
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: NO];
[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 dismissModalViewControllerAnimated: YES];
[self pushNewScreen];
}
-(void) pushNewScreen
{
MainViewController *mainView = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
[self presentModalViewController:mainView animated:YES];
[mainView release];
}
The problem is, when pushNewScreen is called, mainView is not shown... I have gone through each line with the debugger and every line in pushNewScreen is called. Any ideas?
Instead of [self pushNewScreen]; use [self performselector:#selector(pushNewScreen) after delay:0.5f];
It will solve the problem. If not, increase the delay timing.
Thanks to A-Live, I was able to solve it using
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
instead. Hope this helps someone else!

Modal viewController presented from UITabBarController

I have a class that is a subclass of UITabBarController which contains 4 child viewControllers. I've added a button similar to RedLaser, Instagram, Path, DailyBooth, and other apps. Mine is like the top example here:
This button calls a method in the TabBarController which presents a modal viewController. When it's dismissed, the NavigationControllers in the currently selected viewController starts to behave strangely. The pop animation is all messed up and other small bugs happen until you select another tab on the tabBar. Then the animations are fine until the viewController is presented again.
I'm sure it's because I'm dismissing it incorrectly, but I'm not sure how this is to be done.
this is my code in the TabBarController:
-(void)showScanner {
ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology:ZBAR_I25
config:ZBAR_CFG_ENABLE
to:0];
[scanner setSymbology:ZBAR_QRCODE
config:ZBAR_CFG_ENABLE
to:0];
[reader setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:reader
animated:YES];
[reader release];
//[self playBeep];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for (symbol in results)
break;
NSString *barcode = symbol.data;
UINavigationController *searchNavController = [[self viewControllers] objectAtIndex:1];
WLSearchViewController *searchVC = [searchNavController.viewControllers objectAtIndex:0];
// WLSearchViewController *searchVC = [[self viewControllers] objectAtIndex:1];
//[searchNavController popToRootViewControllerAnimated:NO];
[self setSelectedViewController:searchNavController];
[self dismissModalViewControllerAnimated:YES];
[self playBeep];
[searchVC handleSearchForTerm:barcode];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}
Found what was wrong, figured I'd post this to help anyone else who's facing this.
I had overridden a viewDidAppear:animated: in my tabBarController but I didn't call [super viewDidAppear:animated:]
Added that and everything was better!