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