ZXing扫描二维码在iphone中的使用

1、首先要下载zxing2.0.zip;

下载库地址:

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

ViewController.m:

//正常扫描退出事件  
- (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;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值