zoukankan      html  css  js  c++  java
  • 二维码扫描

     

    1.将ZBar的SDK导入工程

     

     

     

     

    SDK下载地址:https://i.cnblogs.com/Files.aspx

    或者去官网下载:https://github.com/bmorton/ZBarSDK

    2.设置依赖库

     需要添加AVFoundation  CoreMedia  CoreVideo QuartzCore libiconv

     

    3.修改工程配置

    1)      Framework Search Path

     

    2)      如果使用xcode7.0以上 ,还需设置:

     

    /*

    4. 版本说明 

     1.3版本 全新支持arm7s arm64 全新支持ARC

     1.2版本 ZC封装的ZBar二维码SDK

     1、更新类名从CustomViewController更改为ZCZBarViewController

     2、删除掉代理的相关代码

     1.1版本 ZC封装的ZBar二维码SDK~

     1、增加block回调

     2、取消代理

     3、增加适配IOS7(ios7在AVFoundation中增加了扫描二维码功能)

     1.0版本 ZC封装的ZBar二维码SDK~1.0版本初始建立

    5. 示例代码

    //扫描二维码

    #import "ZKBarViewController.h"

    //生成二维码

    #import "QRCodeGenerator.h"

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        //生成二维码

        UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)];

        

        imageView.center = self.view.center;

        

        //设置二维码图片

        

        //第一个参数:要生成二维码的原始内容   第二个参数:二维码的清晰度,数值越大,二维码越清晰

        imageView.image = [QRCodeGenerator qrImageForString:@"二维码TEST" imageSize:600];

        

        [self.view addSubview:imageView];

        

        

        //扫描二维码

        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];

        button.frame=CGRectMake(100, 100, 100, 100);

        [button setTitle:@"扫描" forState:UIControlStateNormal];

        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

        [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:button];

    }

    //扫描已有的二维码-通过block

    -(void)buttonClick{

        

        //二维码扫描,BOOL值设置为YES的话表示关闭二维码扫描,只扫描条形码

        ZKBarViewController *bar = [[ZKBarViewController alloc] initWithBlock:^(NSString *str, BOOL isSucceed) {

            if (isSucceed) {

                NSLog(@"%@",str);

            }else{

                NSLog(@"扫描失败");

            }

        }];

        

        [self presentViewController:bar animated:YES completion:nil];

    }

  • 相关阅读:
    [React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber
    [React Intl] Format a Date Relative to the Current Date Using react-intl FormattedRelative
    [React Intl] Format Date and Time Using react-intl FormattedDate and FormattedTime
    [React Intl] Render Content with Markup Using react-intl FormattedHTMLMessage
    带你走进EJB--MDB
    Google Play和基于Feature的过滤 —— Feature 参考手册
    常见排序算法的实现
    Never-build package 'XXXX' requires always-build package 'EhLib70'
    自制的七个C,总结的太好了
    那些有影响力的语言
  • 原文地址:https://www.cnblogs.com/dreamDeveloper/p/5958442.html
Copyright © 2011-2022 走看看