XCode7.2 iOS9.2 測試
首先經過CocoaPods 將ZBarSDK導入工程: pod 'ZBarSDK' spa
而後打開生成的xcworkspace文件 代理
首先咱們建立一個按鈕來執行開始掃描的功能(引入頭文件)code
#import <ZBarSDK.h> - (IBAction)scanAction:(id)sender { //初始化相機控制器 ZBarReaderViewController * reader = [ZBarReaderViewController new]; //設置這個代理並非爲了實現它自身的代理方法而是實現相機的代理方法,由於它自身就遵照了UIImagePickerControllerDelegate reader.readerDelegate = self; //獲取ZBar的掃描器 ZBarImageScanner * scanner = reader.scanner; //Interleaved 2 of 5. @since 0.4 //設置掃描器的基本信息 參數一:維碼的類型 參數二:配置 [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0]; //是否使用備用控制設置 reader.showsZBarControls = YES; //模態出相機 [self presentViewController:reader animated:YES completion:nil]; }
imagePicker代理方法::it
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults]; ZBarSymbol * symbol ; for(symbol in results) break; // 將拍攝的照片展現在imageView當中 _imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; [picker dismissViewControllerAnimated:YES completion:nil]; // 二維碼的信息展現在contentTV上 self.contentTV.text = symbol.data; }
完成了測試吧!!!!!!io