iOS中 二維碼掃描有ZBar 和 ZXing 腹泌。 看了比較 ZBar優(yōu)勢略高凉袱。 基于C語言速度較快 還能掃描條形碼~
直接將ZBar 拖入工程中 我得居然報錯了linker command failed with exit code 1 (use -v to see invocation)
libzbar.a(ZBarCaptureReader.o)' does not contain bitcode.
然后找了解決方法
然后 添加一些依賴
bulabula~正常一般的博客都有的如何使用的代碼#
后面有一個要調(diào)用本地相冊里的二維碼 找了好幾下子才找到运沦。 分享出來
1.創(chuàng)建一個相冊的全局變量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;
}
調(diào)取相冊的時候 有的小伙伴會遇到 你本機設置為中文 但是顯示為英文 標題為photos#
在info.plist里面添加Localized resources can be mixed 為YES 就OK了~
有說的不對的地方 請大家留言告訴我。 互相學習 = =~