ios 二维码扫描

我是用ZBar做的二维码扫描 其他的SDK也可以

首先是导入库文件:

1.AVFoundation.framework

2.CoreMedia.framework

3.CoreVideo.framework

4.QuartzCore.framework

5.libiconv.dylib

这个5个库文件

在ViewController.h 导入#import "ZBarSDK.h" 并且 继承 <ZBarReaderDelegate>协议

1
2
3
@interface ViewController : UIViewController <zbarreaderdelegate> <br>@property (weak, nonatomicIBOutlet UIImageView *imageView;
- (IBAction)scan:(id)sender;
@property (weak, nonatomicIBOutlet UILabel *label;

  

UIImageView/UILabel/UIButton, UIImageView 用于显示扫描到的图像,UILabel用于显示扫描到的信息,UIButton 用于响应事件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
- (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;
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。