XCode7.2 iOS9.2
首先通过CocoaPods 将ZBarSDK导入工程: pod 'ZBarSDK'
然后打开生成的xcworkspace文件
首先我们创建一个按钮来执行开始扫描的功能(引入头文件)
#import <ZBarSDK.h>
- (IBAction)scanAction:(id)sender {
//初始化相机控制器
ZBarReaderViewController * reader = [ZBarReaderViewController new];
//设置这个代理并不是为了实现它自身的代理方法而是实现相机的代理方法,因为它自身就遵守了UIImagePickerControllerDelegate
reader.readerDelegate = self;
//获取ZBar的扫描器
ZBarImageScanner * scanner = reader.scanner;
//Interleaved 2 of 5. @since 0.4
//设置扫描器的基本信息 参数一:维码的类型 参数二:配置
[scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
//是否使用备用控制设置
reader.showsZBarControls = YES;
//模态出相机
[self presentViewController:reader animated:YES completion:nil];
}
imagePicker代理方法::
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
ZBarSymbol * symbol ;
for(symbol in results)
break;
// 将拍摄的照片展示在imageView当中
_imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
// 二维码的信息展示在contentTV上
self.contentTV.text = symbol.data;
}
完成了测试吧!!!!!!