ZBarSDK扫描二维码

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

完成了测试吧!!!!!!

转载于:https://my.oschina.net/742865703/blog/553012

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值