iOS中 二维码扫描有ZBar 和 ZXing 。 看了比较 ZBar优势略高。 基于C语言速度较快 还能扫描条形码~
直接将ZBar 拖入工程中 我得居然报错了linker command failed with exit code 1 (use -v to see invocation)
libzbar.a(ZBarCaptureReader.o)' does not contain bitcode.
然后找了解决方法
然后 添加一些依赖
bulabula~正常一般的博客都有的如何使用的代码#
后面有一个要调用本地相册里的二维码 找了好几下子才找到。 分享出来
1.创建一个相册的全局变量UIImagePickerController *imagePicker;
2.遵守代理<UIImagePickerControllerDelegate>
3.openPhoto
{
NSLog(@"打开相册");
imagePicker = [ZBarReaderController new];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
4.选择了一张图片后
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results) {
NSLog(@"symbol:%@", symbol);
break;
}
[imagePicker dismissViewControllerAnimated:YES completion:nil];
//二维码字符串
NSString *QRCodeString = symbol.data;
UIAlertView * alertView=[[UIAlertView alloc]initWithTitle:QRCodeString message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alertView show];
[self.readerView stop];
}
5.相册图片未检测到条码
-(void)readerControllerDidFailToRead:(ZBarReaderController *)reader withRetry:(BOOL)retry{ if (retry) {
//retry == 1 选择图片为非二维码。
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请选择正确的二维码(:з)∠)" delegate:self cancelButtonTitle:nil otherButtonTitles:@"朕知道了", nil];
[alert show];
[self dismissViewControllerAnimated:YES completion:nil];
}
return;
}
调取相册的时候 有的小伙伴会遇到 你本机设置为中文 但是显示为英文 标题为photos#
在info.plist里面添加Localized resources can be mixed 为YES 就OK了~
FDE6D301-FE21-4B1E-9E98-1476F59A2144.jpg
有说的不对的地方 请大家留言告诉我。 互相学习 = =~