iOS 二维码扫描 通过ZBar ZXing等第三方库

  扫描二维码的开源库有很多如 ZBarZXing

 

ZBar的使用方法:

下载ZBar SDK

地址https://github.com/bmorton/ZBarSDK

 

ZBarSDK是一个开源的SDK,该SDK实现了识别和读取各种条形码,包括EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 QR Code

 

Step1.使用ZBarSDK 需要导入的framework

1.AVFoundation.framework

2.CoreMedia.framework

3.CoreVideo.framework

4.QuartzCore.framework

5.libiconv.dylib

Step2.ViewController.h 导入#import "ZBarSDK.h"

Step3.ViewController.h 实现 <ZBarReaderDelegate>协议

Step4.写代码:

 

- (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;

}

posted @ 2015-11-12 15:38  jgCho  阅读(857)  评论(0编辑  收藏  举报