利用条形码,可以简单的得到二维码的值.
需要注意的几个问题 网上有很多的。a文件 各不相同,有的支持64有的不支持,兼容的比较好的一款我在网上找到了对应的github下载地址https://github.com/wxm5558/libzbar,有需要的朋友去下载吧。代码很简单 我是从别处复制的。最重要的是这个.a文件的下载,库文件引入后 如果报错大部分原因是这个.a的事
具体的实现过程如下:
首先下载zbr的sdk。
然后,创建工程,iphone.scanbar。
第三,把下载的ZBarSDK添加到工程中。
第四,然后添加.framework到工程中。
- -(void)buttonAction:(UIButton *)btn{
- ZBarReaderViewController *reader = [ZBarReaderViewController new];
- reader.readerDelegate = self;
- ZBarImageScanner *scanner = reader.scanner;
- [scanner setSymbology: ZBAR_I25
- config: ZBAR_CFG_ENABLE
- to: 0];
- [self presentModalViewController: reader animated: YES];
- [reader release];
- }
- - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
- {
- NSLog(@"info=%@",info);
- NSLog(@"info is a -------------->%@",info);
- // 得到条形码结果
- id<NSFastEnumeration> results =
- [info objectForKey: ZBarReaderControllerResults];
- ZBarSymbol *symbol = nil;
- for(symbol in results)
- // EXAMPLE: just grab the first barcode
- break;
- // 将获得到条形码显示到我们的界面上
- NSString *str = symbol.data;
- // 扫描时的图片显示到我们的界面上
- NSLog(@"str is a -------------->%@",str);
- if([str hasPrefix:@"http"]){
- NSURL *url = [NSURL URLWithString:str];
- [[UIApplication sharedApplication] openURL:url];
- }else if([str hasPrefix:@"localhost:"]){
- NSString * categoryId = [str substringFromIndex:9];
- NSDictionary *dic = [NSDictionary dictionaryWithObject:categoryId forKey:@"categoryId"];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"goIntoMgzViewNotification" object:self userInfo:dic];
- }else{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"二维码错误,请更换二维码后重试" delegate:self cancelButtonTitle:@"我知道了" otherButtonTitles:nil, nil] ;
- [alert show];
- [alert release];
- alert = nil;
- }
- // resultImage.image =
- [info objectForKey: UIImagePickerControllerOriginalImage];
- // 扫描界面退出
- [reader dismissModalViewControllerAnimated: YES];