Implementing ZBar QR Code Reader in UIView

Posted by Bobster4300 on Stack Overflow See other posts from Stack Overflow or by Bobster4300
Published on 2012-12-16T05:00:18Z Indexed on 2012/12/16 5:03 UTC
Read the original article Hit count: 376

Filed under:
|
|
|
|

I really need help here. I'm pretty new to iOS/Objective-C so sorry if the problem resolution is obvious or if my code is terrible. Be easy on me!! :-)

I'm struggling to integrate ZBarSDK for reading QR Codes into an iPad app i'm building. If I use ZBarReaderController (of which there are plenty of tutorials and guides on implementing), it works fine. However I want to make the camera come up in a UIView as opposed to the fullscreen camera.

Now I have gotten as far as making the camera view (readerView) come up in the UIView (ZBarReaderView) as expected, but I get an error when it scans a code. The error does not come up until a code is scanned making me believe this is either delegate related or something else.

Here's the important parts of my code: (ZBarSDK.h is imported at the PCH file)

SignInViewController.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@class AVCaptureSession, AVCaptureDevice;

@interface SignInViewController : UIViewController
< ZBarReaderDelegate >
{
    ZBarReaderView *readerView;
    UITextView *resultText;
}

@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (strong, nonatomic) IBOutlet UITextView *resultText;
@property (strong, nonatomic) IBOutlet ZBarReaderView *readerView;

-(IBAction)StartScan:(id) sender;

SignInViewController.m

#import "SignInViewController.h"

@interface SignInViewController ()

@end

@implementation SignInViewController


@synthesize resultText, readerView;

-(IBAction)StartScan:(id) sender
{
readerView = [ZBarReaderView new];
readerView.readerDelegate = self;

readerView.tracksSymbols = NO;

readerView.frame = CGRectMake(30,70,230,230);
readerView.torchMode = 0;
readerView.device = [self frontFacingCameraIfAvailable];

ZBarImageScanner *scanner = readerView.scanner;
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];


[self relocateReaderPopover:[self interfaceOrientation]];

[readerView start];

[self.view addSubview: readerView];
resultText.hidden=NO;

}


- (void) readerControllerDidFailToRead: (ZBarReaderController*) reader
                         withRetry: (BOOL) retry{
NSLog(@"the image picker failing to read");

}

- (void) imagePickerController: (UIImagePickerController*) reader     didFinishPickingMediaWithInfo: (NSDictionary*) info
{


NSLog(@"the image picker is calling successfully %@",info);
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
NSString *hiddenData;
for(symbol in results)
    hiddenData=[NSString stringWithString:symbol.data];


NSLog(@"the symbols  is the following %@",symbol.data);

resultText.text=symbol.data;


NSLog(@"BARCODE= %@",symbol.data);

NSLog(@"SYMBOL : %@",hiddenData);
resultText.text=hiddenData;

}

The error I get when a code is scanned:

2012-12-16 14:28:32.797 QRTestApp[7970:907] -[SignInViewController     readerView:didReadSymbols:fromImage:]: unrecognized selector sent to instance 0x1e88b1c0
2012-12-16 14:28:32.799 QRTestApp[7970:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SignInViewController readerView:didReadSymbols:fromImage:]: unrecognized selector sent to instance 0x1e88b1c0'

I'm not too worried about what happens with the results just yet, just want to get over this error. Took me ages just to get the camera to come up in the UIView due to severe lack of tutorial or documentation on ZBarReaderView (for beginners anyway). Thanks all.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios