下载库地址:
http://code.google.com/p/zxing/
点击进入下载页
2、解压压缩包
里面只保留 cpp 和 iphone 两个文件夹就可以了;然后创建项目zxingtest;把zxing-2.0拷贝到与你项目同级的目录下:
打开项目,导入ZXingWidget.xcodeproj文件,注意不要勾选copy,并且要选择refrence:
3、选择项目,build phases添加库:
4、设置Build Settings下的"header search paths":
5、在项目中引用文件
请把appdelegate.m文件改成adddelegate.mm,viewcontroller.m改成viewcontroller.mm文件,如果不改的话就有什么找不到文件的错误信息;
ViewController.xib文件如图:
ViewController.h:
#import <UIKit/UIKit.h> #import "ZXingWidgetController.h" #import "QRCodeReader.h" @interface ViewController : UIViewController<ZXingDelegate>{ UITextView *resultsView; NSString *resultsToDisplay; } @property (retain, nonatomic) IBOutlet UITextView *resultsView; @property (nonatomic, copy) NSString *resultsToDisplay; - (IBAction)scanPressed:(id)sender; @end
//正常扫描退出事件 - (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result { self.resultsToDisplay = result; if (self.isViewLoaded) { [resultsView setText:resultsToDisplay]; [resultsView setNeedsDisplay]; } [self dismissModalViewControllerAnimated:NO]; } //扫描界面退出按钮事件 - (void)zxingControllerDidCancel:(ZXingWidgetController*)controller { [self dismissModalViewControllerAnimated:YES]; } //扫描按钮事件 - (IBAction)scanPressed:(id)sender { ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO]; QRCodeReader *qrcodeReader = [[QRCodeReader alloc] init]; NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil]; [qrcodeReader release]; widController.readers = readers; [readers release]; NSBundle *mainBundle = [NSBundle mainBundle]; //aiff widController.soundToPlay =[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO]; [self presentModalViewController:widController animated:YES]; [widController release]; }
二维码测试:
还有,必须在真机上测试
demo下载地址:http://download.csdn.net/download/rhljiayou/4515394
参考博客:http://blog.csdn.net/icash/article/details/7727299;