码迷,mamicode.com
首页 > 移动开发 > 详细

ios 二维码扫描

时间:2015-02-23 00:13:55      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

https://github.com/bmorton/ZBarSDK

我是用ZBar做的二维码扫描 其他的SDK也可以

首先是导入库文件:

1.AVFoundation.framework

2.CoreMedia.framework

3.CoreVideo.framework

4.QuartzCore.framework

5.libiconv.dylib

这个5个库文件

在ViewController.h 导入#import "ZBarSDK.h" 并且 继承 <ZBarReaderDelegate>协议

@interface ViewController : UIViewController <zbarreaderdelegate> 
@property (weak, nonatomic) IBOutlet UIImageView *imageView; - (IBAction)scan:(id)sender; @property (weak, nonatomic) IBOutlet UILabel *label;

  

UIImageView/UILabel/UIButton, UIImageView 用于显示扫描到的图像,UILabel用于显示扫描到的信息,UIButton 用于响应事件

- (IBAction)scan:(id)sender {
     
     
    ZBarReaderViewController * reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    ZBarImageScanner * scanner = reader.scanner;
    [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
 
    reader.showsZBarControls = YES;
     
    [self presentViewController:reader animated:YES completion:nil];
   
     
}
 
 
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    id<nsfastenumeration> results = [info objectForKey:ZBarReaderControllerResults];
    ZBarSymbol * symbol;
    for(symbol in results)
        break;
     
    _imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
     
    [picker dismissViewControllerAnimated:YES completion:nil];
     
    _label.text = symbol.data;
}
 

  

ios 二维码扫描

标签:

原文地址:http://www.cnblogs.com/JJFly/p/4297821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!