LXDScanCodeController.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // LXDScanCodeController.m
  3. // LXDScanQRCode
  4. //
  5. // Created by 林欣达 on 15/10/14.
  6. // Copyright © 2015年 cnpayany. All rights reserved.
  7. //
  8. #import "LXDScanCodeController.h"
  9. #import "LXDScanView.h"
  10. @interface LXDScanCodeController ()<LXDScanViewDelegate>
  11. @property (nonatomic, strong) LXDScanView * scanView;
  12. @end
  13. @implementation LXDScanCodeController
  14. #pragma mark - initial
  15. + (instancetype)scanCodeController
  16. {
  17. return [[self alloc] init];
  18. }
  19. - (instancetype)init
  20. {
  21. if (self = [super init]) {
  22. self.scanView = [LXDScanView scanViewShowInController: self];
  23. }
  24. return self;
  25. }
  26. #pragma mark - life
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.view.backgroundColor = [UIColor whiteColor];
  30. [self.view addSubview: self.scanView];
  31. }
  32. - (void)viewWillAppear:(BOOL)animated
  33. {
  34. [super viewWillAppear: animated];
  35. [self.scanView start];
  36. }
  37. - (void)viewDidDisappear:(BOOL)animated
  38. {
  39. [super viewDidDisappear: animated];
  40. [self.scanView stop];
  41. }
  42. - (void)didReceiveMemoryWarning {
  43. [super didReceiveMemoryWarning];
  44. }
  45. - (void)dealloc
  46. {
  47. [self.scanView stop];
  48. }
  49. #pragma mark - LXDScanCodeController
  50. /**
  51. * 扫描成功时回调
  52. */
  53. - (void)scanView:(LXDScanView *)scanView codeInfo:(NSString *)codeInfo
  54. {
  55. if ([_scanDelegate respondsToSelector: @selector(scanCodeController:codeInfo:)]) {
  56. [_scanDelegate scanCodeController: self codeInfo: codeInfo];
  57. [self.navigationController popViewControllerAnimated: YES];
  58. } else {
  59. [[NSNotificationCenter defaultCenter] postNotificationName: LXDSuccessScanQRCodeNotification object: self userInfo: @{ LXDScanQRCodeMessageKey: codeInfo }];
  60. }
  61. }
  62. @end