QRCodeScanViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. //
  2. // QRCodeScanViewController.m
  3. // 隐私保护
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "QRCodeScanViewController.h"
  8. #import <AVFoundation/AVFoundation.h>
  9. #import <ImageIO/ImageIO.h>
  10. #import "GuideViewController.h"
  11. #import "RSATool.h"
  12. #import <TZImageManager.h>
  13. #import <TZImagePickerController.h>
  14. #import "connectDeviceManager.h"
  15. @interface QRCodeScanViewController ()<AVCaptureMetadataOutputObjectsDelegate,AVCaptureVideoDataOutputSampleBufferDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,TZImagePickerControllerDelegate>
  16. @property(nonatomic,strong)AVCaptureVideoPreviewLayer *layer;
  17. //捕捉会话
  18. @property(nonatomic,strong)AVCaptureSession *session;
  19. //辅助区域框
  20. @property(nonatomic,strong)UIImageView * cyanEdgeImageView;
  21. @property(nonatomic,strong)UIImageView * qrCodeScanLine;
  22. @property(nonatomic,strong)NSTimer * scanLineTimer;
  23. ////打开灯光btn,默认为hidden
  24. //
  25. //@property(nonatomic,strong)UIButton * lightBtn;
  26. //
  27. ////获取相册图片进行扫描
  28. //
  29. //@property(nonatomic,strong)UIButton * photoBtn;
  30. @end
  31. @implementation QRCodeScanViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. [self.navigationBar setHidden:YES];
  36. [self.toolBar setHidden:YES];
  37. AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  38. //判断摄像头状态是否可用
  39. if(authStatus==AVAuthorizationStatusAuthorized){
  40. [self startScan];
  41. }else{
  42. NSLog(@"未开启相机权限,请前往设置中开启");
  43. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  44. if (granted){
  45. mainBlock(^{
  46. [self startScan];
  47. });
  48. }
  49. }];
  50. }
  51. }
  52. -(void)viewWillDisappear:(BOOL)animated
  53. {
  54. [super viewWillDisappear:animated];
  55. if(_scanLineTimer)[_scanLineTimer invalidate];
  56. }
  57. //开始扫描二维码
  58. -(void)startScan{
  59. //1.创建捕捉会话,AVCaptureSession是第一个要被创建的对象,所有的操作都要基于这一个session
  60. self.session = [[AVCaptureSession alloc]init];
  61. AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  62. AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
  63. [self.session addInput:input];
  64. //3.添加输出数据(示例对象-->类对象-->元类对象-->根元类对象)
  65. /*输入的类是AVCaptureInput,那么输出的类相应的就应该是AVCaptureOutput。
  66.  输出不需要和设备挂钩,因为一般情况下,我们的输出要么是音频或视频文件,要么是一些其他的数据,像二维码扫描一般是字符串类型。
  67.  所以创建AVCaptureOutput实例就不需要AVCaptureDevice对象。
  68.  AVCaptureOutput也同样是一个抽象类,同样要使用其子类,在这里我们扫描二维码,
  69.  使用的是AVCaptureMetadataOutput,设置代码如下所示*/
  70. AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
  71. [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
  72. //设置能扫描的区域,这里注意,CGRectMake的x,y和width,height的值是互换位置
  73. output.rectOfInterest=CGRectMake(250/self.view.frame.size.height, 100/self.view.frame.size.width, (self.view.frame.size.width-200)/self.view.frame.size.width, (self.view.frame.size.width-200)/self.view.frame.size.width);
  74. [self.session addOutput:output];
  75. //设置输入元数据的类型(类型是二维码,条形码数据,注意,这个一定要写在添加到session后面,不然要崩溃,如果只需要扫描二维码只需要AVMetadataObjectTypeQRCode,如果还需要扫描条形码,那么全部添加上)
  76. [output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode,
  77. AVMetadataObjectTypeEAN8Code,
  78. AVMetadataObjectTypeEAN13Code,
  79. AVMetadataObjectTypeCode39Code,
  80. AVMetadataObjectTypeCode39Mod43Code,
  81. AVMetadataObjectTypeCode93Code,
  82. AVMetadataObjectTypeCode128Code,
  83. AVMetadataObjectTypePDF417Code,
  84. AVMetadataObjectTypeAztecCode,
  85. AVMetadataObjectTypeUPCECode,
  86. AVMetadataObjectTypeInterleaved2of5Code,
  87. AVMetadataObjectTypeITF14Code,
  88. AVMetadataObjectTypeDataMatrixCode,
  89. ]];
  90. //4.添加扫描图层
  91. self.layer = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
  92. self.layer.videoGravity=AVLayerVideoGravityResizeAspectFill;
  93. self.layer.frame = self.view.bounds;
  94. [self.view.layer addSublayer:self.layer];
  95. //5.创建view,通过layer层进行设置边框宽度和颜色,用来辅助展示扫描的区域
  96. _cyanEdgeImageView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 250, self.view.frame.size.width-200, self.view.frame.size.width-200)];
  97. // _cyanEdgeImageView.layer.borderWidth=2;
  98. //
  99. // _cyanEdgeImageView.layer.borderColor =[UIColor cyanColor].CGColor;
  100. _cyanEdgeImageView.image = [UIImage imageNamed:@"qrCode_scan_bg"];
  101. [self.view addSubview:_cyanEdgeImageView];
  102. _qrCodeScanLine=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-200, 1)];
  103. _qrCodeScanLine.image = [UIImage imageNamed:@"qrCode_scan_line"];
  104. [_cyanEdgeImageView addSubview:_qrCodeScanLine];
  105. _scanLineTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(scanLineDownAndUpFun) userInfo:nil repeats:YES];
  106. UILabel *tipLib = [[UILabel alloc] initWithFrame:CGRectMake(20, _cyanEdgeImageView.hw_max_y + 15, SCREEN_W - 40, 20)];
  107. tipLib.text = NSLocalizedString(@"guide_qrcoede_tips_please",nil);
  108. tipLib.font = [UIFont systemFontOfSize:14.0];
  109. tipLib.textAlignment = NSTextAlignmentCenter;
  110. tipLib.textColor = [UIColor whiteColor];
  111. [self.view addSubview:tipLib];
  112. //6.创建检测光感源
  113. AVCaptureVideoDataOutput *guangOutPut = [[AVCaptureVideoDataOutput alloc] init];
  114. [guangOutPut setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
  115. //设置为高质量采集率
  116. [self.session setSessionPreset:AVCaptureSessionPresetHigh];
  117. //把光感源添加到会话
  118. [self.session addOutput:guangOutPut];
  119. // self.lightBtn=[[UIButton alloc]initWithFrame:CGRectMake(150, cyanView.frame.origin.y+cyanView.frame.size.height+100, self.view.frame.size.width-300, self.view.frame.size.width-300)];
  120. //
  121. // self.lightBtn.backgroundColor=[UIColor grayColor];
  122. //
  123. // [self.lightBtn addTarget:self action:@selector(lightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  124. //
  125. //打开相册
  126. UIButton *openAlbunBut = [[UIButton alloc] init];
  127. [openAlbunBut setTitle:NSLocalizedString(@"guide_qrcoede_open_album",nil) forState:UIControlStateNormal];
  128. [openAlbunBut setTitleColor:[UIColor hwColor:@"#3B7FFF" alpha:1.0] forState:UIControlStateNormal];
  129. openAlbunBut.titleLabel.font = [UIFont systemFontOfSize:14.0];
  130. [openAlbunBut addTarget:self action:@selector(photoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  131. openAlbunBut.backgroundColor = [UIColor hwColor:@"#FFFFFF" alpha:0.2];
  132. [self.view addSubview:openAlbunBut];
  133. openAlbunBut.layer.cornerRadius = 24;
  134. openAlbunBut.layer.masksToBounds = YES;
  135. [openAlbunBut mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.width.mas_equalTo(140);
  137. make.height.mas_equalTo(48);
  138. make.centerX.mas_equalTo(0);
  139. make.bottom.mas_equalTo(-80);
  140. }];
  141. // [self.view addSubview:self.lightBtn];
  142. // self.photoBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, self.lightBtn.frame.origin.y+self.lightBtn.frame.size.height+50, self.view.frame.size.width-200, 50)];
  143. // [self.photoBtn setTitle:@"相册" forState:UIControlStateNormal];
  144. // [self.photoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  145. // self.photoBtn.backgroundColor=[UIColor orangeColor];
  146. // [self.photoBtn addTarget:self action:@selector(photoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  147. // [self.view addSubview:self.photoBtn];
  148. //9.开始扫描
  149. KWeakSelf
  150. globalBlock(^{
  151. [weakSelf.session startRunning];
  152. });
  153. //添加返回键
  154. CGFloat btn_w_h = 40;
  155. CGFloat btn_show = 28;
  156. UIButton *backBtn = [[UIButton alloc] init];
  157. [self.view addSubview:backBtn];
  158. [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.top.mas_equalTo(H_STATE_BAR + (64.f - btn_w_h)/2.f);
  160. make.left.mas_equalTo(10);
  161. make.width.mas_equalTo(btn_w_h);
  162. make.height.mas_equalTo(btn_w_h);
  163. }];
  164. [backBtn setImage:[UIImage imageNamed:@"icon_base_back"] forState:(UIControlStateNormal)];
  165. [backBtn setImageEdgeInsets:(UIEdgeInsetsMake((btn_w_h - btn_show)/2.f, (btn_w_h - btn_show)/2.f, (btn_w_h - btn_show)/2.f, (btn_w_h - btn_show)/2.f))];
  166. [backBtn addTarget:self
  167. action:@selector(backBtnPressed)
  168. forControlEvents:(UIControlEventTouchUpInside)];
  169. }
  170. #pragma mark timer 处理线上下移动
  171. bool isDownType = YES;
  172. -(void)scanLineDownAndUpFun
  173. {
  174. [UIView animateWithDuration:0.01 animations:^{
  175. if(isDownType && self->_qrCodeScanLine.hw_y <= self->_cyanEdgeImageView.hw_h){
  176. self->_qrCodeScanLine.hw_y += 2;
  177. if(self->_cyanEdgeImageView.hw_h - self->_qrCodeScanLine.hw_y <= 5){
  178. isDownType = NO;
  179. }
  180. }
  181. else if(!isDownType && self->_qrCodeScanLine.hw_y >= 0)
  182. {
  183. self->_qrCodeScanLine.hw_y -= 2;
  184. if(self->_qrCodeScanLine.hw_y <= 5){
  185. isDownType = YES;
  186. }
  187. }
  188. }];
  189. }
  190. //实现扫描的回调代理方法
  191. - (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputMetadataObjects:(NSArray*)metadataObjects fromConnection:(AVCaptureConnection*)connection{
  192. //如果数组metadataObjects中有数据,metadataObjects是个数组类型
  193. if(metadataObjects.count>0) {
  194. AVMetadataMachineReadableCodeObject*object = [metadataObjects lastObject];
  195. NSLog(@"%@",object.stringValue);
  196. /*扫描到有用信息时取消扫描*/
  197. NSString *resStr = object.stringValue;//RK3908P1V62112465
  198. [self handleScanCodeResultFun:resStr];
  199. }
  200. else{
  201. [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
  202. NSLog(@"没有扫描到数据");
  203. }
  204. }
  205. #pragma mark 处理扫码出来的数据
  206. - (void)handleScanCodeResultFun:(NSString*)resultStr
  207. {
  208. NSString * resStr = resultStr;
  209. if(resStr.length > 22)
  210. {
  211. NSString*desStr = [RSATool AES128Decrypt:resStr key:AESCODEKEEYY];
  212. if(desStr){//能解码
  213. resStr = desStr;
  214. }
  215. }
  216. //Ch0IKJCY9lOgokjfPBFE1cowdC1+tj7ywB2pZgSzjhc=
  217. //sgl5OzDoVjY5SmGuL50/EnQ4n6Kw+DzRiE1oUjq7yAM=
  218. if (([resStr containsString:@"RK"] && (resStr.length == @"RK3908P1V62112465".length))
  219. || resStr.length == @"0333933700223250017273".length
  220. ){
  221. [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_ok",nil)] show];
  222. [_scanLineTimer invalidate];
  223. // NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:resStr,Const_Have_Add_Device_SN, nil];
  224. // [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
  225. [self nextStep:resStr];
  226. //停止扫描
  227. [self.session stopRunning];
  228. //移除扫描层layer
  229. [self.layer removeFromSuperlayer];
  230. }
  231. else{
  232. [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
  233. }
  234. }
  235. - (void)nextStep:(NSString *)sn{
  236. KWeakSelf
  237. // [[connectDeviceManager shareInstance] getThridMsgBySN:sn needReconnect:NO didNetEnd:^(NSInteger didSuc) {
  238. // if(didSuc == 1){
  239. // [weakSelf gotoGuideViewFunBy:sn];
  240. // }else{
  241. //// if(didSuc == 2){
  242. //// [[iToast makeText:NSLocalizedString(@"scan_sn_data_error_tip",nil)] show];
  243. //// }
  244. //// else{
  245. //// [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_get_SdnID_fail",nil)] show];
  246. //// }
  247. // if(self->_didScanErrorFun){
  248. // self->_didScanErrorFun(didSuc);
  249. // }
  250. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  251. // [self.navigationController popViewControllerAnimated:YES];
  252. // });
  253. // }
  254. // }];
  255. [[netWorkManager shareInstance] getThridMsgBySN:sn success:^(id _Nonnull responseObject) {
  256. DeviceThirdIdModel *model = responseObject;
  257. if([model isKindOfClass:[DeviceThirdIdModel class]]){
  258. if(model.status == 0 && model.data){
  259. [weakSelf gotoGuideViewFunBy:sn];
  260. }
  261. else{
  262. NSInteger state = 2;
  263. if (model.status == 201 || model.status == 202) {
  264. state = model.status;
  265. }
  266. if(self->_didScanErrorFun){
  267. self->_didScanErrorFun(state);
  268. }
  269. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  270. [self.navigationController popViewControllerAnimated:YES];
  271. });
  272. }
  273. }
  274. else{
  275. if(self->_didScanErrorFun){
  276. self->_didScanErrorFun(2);
  277. }
  278. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  279. [self.navigationController popViewControllerAnimated:YES];
  280. });
  281. }
  282. } failure:^(NSError * _Nonnull error) {
  283. if(self->_didScanErrorFun){
  284. self->_didScanErrorFun(0);
  285. }
  286. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  287. [self.navigationController popViewControllerAnimated:YES];
  288. });
  289. }];
  290. }
  291. #pragma mark GuideViewController
  292. - (void)gotoGuideViewFunBy:(NSString*)sn
  293. {
  294. //数据埋点
  295. [[netWorkManager shareInstance] DataEmbeddingPointBy:0 withEventValue:@"Scan_code"];
  296. NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:sn,Const_Have_Add_Device_SN, nil];
  297. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:newDict];
  298. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background) value:YES];
  299. /*下一步*/
  300. GuideViewController *nextVC = [[GuideViewController alloc] init];
  301. nextVC.sn = sn;
  302. [self.navigationController pushViewController:nextVC animated:YES];
  303. }
  304. //光感传感器代理
  305. -(void)captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection{
  306. //获取光线的值
  307. CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL,sampleBuffer, kCMAttachmentMode_ShouldPropagate);
  308. NSDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(__bridge NSDictionary*)metadataDict];
  309. CFRelease(metadataDict);
  310. NSDictionary *exifMetadata = [[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy];
  311. float brightnessValue = [[exifMetadata objectForKey:(NSString*)kCGImagePropertyExifBrightnessValue]floatValue];
  312. NSLog(@"%f",brightnessValue);
  313. // 根据brightnessValue的值来打开和关闭闪光灯,一般值小于0就需要打开,大于0就关闭
  314. // if((brightnessValue <0)) {//显示闪光灯
  315. // self.lightBtn.hidden=NO;
  316. // }else if((brightnessValue >0)) {//隐藏闪光灯
  317. // self.lightBtn.hidden=YES;
  318. // }
  319. }
  320. ////闪光灯按钮点击方法
  321. //
  322. //-(void)lightBtnClick:(UIButton*)sender{
  323. // //判断当前设备是否有闪光灯
  324. //
  325. // AVCaptureDevice * device=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  326. //
  327. // BOOL result=[device hasTorch];
  328. //
  329. // if(result==YES){
  330. // if(self.lightBtn.isSelected==NO){
  331. // self.lightBtn.selected=YES;
  332. // self.lightBtn.backgroundColor=[UIColor greenColor];
  333. // [device lockForConfiguration:nil];
  334. // [device setTorchMode: AVCaptureTorchModeOn];//开
  335. // [device unlockForConfiguration];
  336. // }else if(self.lightBtn.isSelected==YES){
  337. // self.lightBtn.selected=NO;
  338. // self.lightBtn.backgroundColor=[UIColor grayColor];
  339. // [device lockForConfiguration:nil];
  340. // [device setTorchMode: AVCaptureTorchModeOff];//关
  341. // [device unlockForConfiguration];
  342. // }
  343. // }else{
  344. // NSLog(@"当前设备闪光灯不可用");
  345. // }
  346. //}
  347. //
  348. ////获取相册图片btn点击方法
  349. -(void)photoBtnClick:(UIButton*)sender{
  350. // UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  351. // imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  352. // // imagePicker.allowsEditing = YES;
  353. // imagePicker.delegate=self;
  354. // [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
  355. [self photoClickFun];
  356. }
  357. - (void)photoClickFun
  358. {
  359. TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
  360. imagePicker.allowPickingVideo=NO;
  361. //imagePicker.isStatusBarDefault=YES;
  362. imagePicker.allowTakePicture=NO;
  363. imagePicker.allowPreview = NO;
  364. // 4. 照片排列按修改时间升序
  365. imagePicker.sortAscendingByModificationDate = YES;
  366. [self presentViewController:imagePicker animated:YES completion:nil];
  367. }
  368. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto
  369. {
  370. if(photos && photos.count >= 1){
  371. [self detectImageFunBy:photos.firstObject];
  372. }
  373. else{
  374. [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
  375. }
  376. }
  377. //UIImagePickerControllerDelegate选择图片的回调
  378. -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
  379. //把UIimage类型转换成CIimage类型
  380. UIImage *pickedImage = info[UIImagePickerControllerEditedImage] ?: info[UIImagePickerControllerOriginalImage];
  381. [picker dismissViewControllerAnimated:YES completion:^{
  382. }];
  383. [self detectImageFunBy:pickedImage];
  384. }
  385. #pragma mark 解析Uiimage
  386. - (void)detectImageFunBy:(UIImage*)pickedImage
  387. {
  388. CIImage*detectImage = [CIImage imageWithData:UIImagePNGRepresentation(pickedImage)];
  389. //解析扫描二维码结果字符串
  390. CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy: CIDetectorAccuracyLow}];
  391. //CIQRCodeFeature*feature = (CIQRCodeFeature*)[detector featuresInImage:detectImage options:nil].firstObject;
  392. NSArray *messageStringArr = (CIQRCodeFeature*)[detector featuresInImage:detectImage options:nil];
  393. //排除掉 http的
  394. __block NSString *curQRCodeStr = nil;
  395. for(CIQRCodeFeature*feature in messageStringArr){
  396. if([feature.messageString rangeOfString:@"http"].location == NSNotFound){
  397. curQRCodeStr = feature.messageString;
  398. break;
  399. }
  400. }
  401. if(curQRCodeStr) {
  402. NSLog(@"=================二维码结果为%@",curQRCodeStr);
  403. [self handleScanCodeResultFun:curQRCodeStr];
  404. }else{
  405. [[iToast makeText:NSLocalizedString(@"guide_qrcoede_tips_error",nil)] show];
  406. NSLog(@"没有扫描到数据");
  407. }
  408. // //停止会话对象扫描
  409. // [self.session stopRunning];
  410. // //移除扫描层layer
  411. // [self.layer removeFromSuperlayer];
  412. }
  413. @end