二维码扫描

//导入第三方 #import "ZBarSDK.h"

//导入协议

// 拖拽定义属性

@property (weak, nonatomic) IBOutlet UIImageView *myImageView;

@property (weak, nonatomic) IBOutlet UILabel *myLabel;

//方法

@implementation ViewController

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{    //先获取扫描结果    idresult = [info objectForKey:ZBarReaderControllerResults];

ZBarSymbol *symbol = nil;

for (symbol in result)

{

break;

}

//在图片视图中显示扫描过的二维码

self.myImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

//退出照相机全屏

[self dismissViewControllerAnimated:YES completion:nil];

self.myLabel.text = symbol.data;

//跳转到连接中

NSURL *url = [NSURL URLWithString:symbol.data]

;

[[UIApplication sharedApplication] openURL:url];

}

- (void) readerControllerDidFailToRead: (ZBarReaderController*) reader

withRetry: (BOOL) retry

{

}

- (void) readerView: (ZBarReaderView*) readerView

didReadSymbols: (ZBarSymbolSet*) symbols

fromImage: (UIImage*) image

{

}

- (IBAction)theBtn:(id)sender {

//初始化相机控制器

ZBarReaderViewController *reader = [ZBarReaderViewController new];

//设置代理

reader.readerDelegate = self;

//基本适配

reader.supportedOrientationsMask = ZBarOrientationMaskAll;

//二维码/条形码识别设置

ZBarImageScanner *scanner = reader.scanner;

[scanner setSymbology: ZBAR_I25

config: ZBAR_CFG_ENABLE

to: 0];

//弹出系统照相机,全屏拍摄

[self presentModalViewController: reader

animated: YES];

}

- (void)viewDidLoad {

[super viewDidLoad];

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

}

@end

你可能感兴趣的:(二维码扫描)