标签:
1. 从 http://zbar.sourceforge.net/iphone 下载最新版本的ZBar SDK。
2. 双击下载好的文件。目前版本是:ZBarSDK-1.2.dmg。
3. 按提示将ZBarSDK拖拽到我们自己的项目中。
4. 使用ZBarSDK,还需要导入其他的framework。
工程 -> target -> build phases -> Link Binary With Libraries -> 点击+添加以下framework。
1>.AVFoundation.framework
2>.CoreMedia.framework
3>.CoreVideo.framework
4>.QuartzCore.framework
5>.libiconv.dylib
5. 导入头文件:#import "ZBarSDK.h"
6. 声明支持代理协议:<ZBarReaderDelegate>
7. 书写代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"二维码扫描"; UIImageView * imageView = [[UIImageView alloc] init]; [imageView setFrame:CGRectMake(300, 162, 424, 424)]; [self.view addSubview:imageView]; self.resultImage = imageView; [self scan]; } - (void)scan {
// ZBarReaderViewController * reader = [[ZBarReaderViewController alloc] init]; reader.readerDelegate = self; reader.supportedOrientationsMask = ZBarOrientationMaskAll; ZBarImageScanner * scanner = reader.scanner; [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0]; [self presentViewController:reader animated:YES completion:nil]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// 得到条形码结果
id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults]; ZBarSymbol * symbol = nil; for (symbol in results) { break; }
// 打印条形码
self.resultImage.image = [info objectForKey:UIImagePickerControllerOriginalImage]; [picker dismissViewControllerAnimated:YES completion:nil];
// 退出扫描界面
MyLog(@"result:%@", symbol.data); }
标签:
原文地址:http://www.cnblogs.com/ljios/p/4429376.html