DIYScanViewController.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // DIYScanViewController.m
  3. // LBXScanDemo
  4. //
  5. // Created by lbxia on 2017/6/5.
  6. // Copyright © 2017年 lbx. All rights reserved.
  7. //
  8. #import "DIYScanViewController.h"
  9. #import "LBXAlertAction.h"
  10. @interface DIYScanViewController ()
  11. @end
  12. @implementation DIYScanViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. self.cameraInvokeMsg = @"相机启动中";
  17. }
  18. #pragma mark -实现类继承该方法,作出对应处理
  19. - (void)scanResultWithArray:(NSArray<LBXScanResult*>*)array
  20. {
  21. if (!array || array.count < 1)
  22. {
  23. [self popAlertMsgWithScanResult:nil];
  24. return;
  25. }
  26. //经测试,可以ZXing同时识别2个二维码,不能同时识别二维码和条形码
  27. // for (LBXScanResult *result in array) {
  28. //
  29. // NSLog(@"scanResult:%@",result.strScanned);
  30. // }
  31. LBXScanResult *scanResult = array[0];
  32. NSString*strResult = scanResult.strScanned;
  33. self.scanImage = scanResult.imgScanned;
  34. if (!strResult) {
  35. [self popAlertMsgWithScanResult:nil];
  36. return;
  37. }
  38. //TODO: 这里可以根据需要自行添加震动或播放声音提示相关代码
  39. //...
  40. [self showNextVCWithScanResult:scanResult];
  41. }
  42. - (void)popAlertMsgWithScanResult:(NSString*)strResult
  43. {
  44. if (!strResult) {
  45. strResult = @"识别失败";
  46. }
  47. __weak __typeof(self) weakSelf = self;
  48. [LBXAlertAction showAlertWithTitle:@"扫码内容" msg:strResult buttonsStatement:@[@"知道了"] chooseBlock:^(NSInteger buttonIdx) {
  49. [weakSelf reStartDevice];
  50. }];
  51. }
  52. - (void)showNextVCWithScanResult:(LBXScanResult*)strResult
  53. {
  54. NSLog(strResult.imgScanned);
  55. // ScanResultViewController *vc = [ScanResultViewController new];
  56. // vc.imgScan = strResult.imgScanned;
  57. //
  58. // vc.strScan = strResult.strScanned;
  59. //
  60. // vc.strCodeType = strResult.strBarCodeType;
  61. //
  62. // [self.navigationController pushViewController:vc animated:YES];
  63. }
  64. @end