//導(dǎo)入第三方 #import "ZBarSDK.h"
//導(dǎo)入?yún)f(xié)議<ZBarReaderDelegate,ZBarReaderViewDelegate>
// 拖拽定義屬性
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
//方法
@implementation ViewController
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{? ? //先獲取掃描結(jié)果? ? idresult = [info objectForKey:ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for (symbol in result)
{
break;
}
//在圖片視圖中顯示掃描過(guò)的二維碼
self.myImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
//退出照相機(jī)全屏
[self dismissViewControllerAnimated:YES completion:nil];
self.myLabel.text = symbol.data;
//跳轉(zhuǎn)到連接中
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 {
//初始化相機(jī)控制器
ZBarReaderViewController *reader = [ZBarReaderViewController new];
//設(shè)置代理
reader.readerDelegate = self;
//基本適配
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
//二維碼/條形碼識(shí)別設(shè)置
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
//彈出系統(tǒng)照相機(jī)翠订,全屏拍攝
[self presentModalViewController: reader
animated: YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
@end