标签:
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; }
标签:
原文地址:http://www.cnblogs.com/JJFly/p/4297821.html