HomeHubSearchViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // HomeHubSearchViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 5. 11..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "HomeHubSearchViewController.h"
  9. @interface HomeHubSearchViewController () {
  10. NSTimer *_timer;
  11. NSInteger _elapsedSeconds;
  12. BLEServiceHandler *bleService;
  13. }
  14. @end
  15. @implementation HomeHubSearchViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self prepareViewDidLoad];
  19. }
  20. - (void)didReceiveMemoryWarning {
  21. [super didReceiveMemoryWarning];
  22. }
  23. - (void)viewWillAppear:(BOOL)animated{
  24. [super viewWillAppear:animated];
  25. bleService.delegate = self;
  26. [self initUI];
  27. UIViewController *vc = [CommonUtil currentViewController];
  28. NSLog(@"vc : %@", vc);
  29. NSLog(@"navi : %@", vc.navigationController);
  30. NSLog(@"vc navi cons : %@", vc.navigationController.viewControllers);
  31. }
  32. - (void)viewWillDisappear:(BOOL)animated {
  33. [super viewWillDisappear:animated];
  34. bleService.delegate = nil;
  35. }
  36. - (void)initUI {
  37. [self startLoading:YES];
  38. [bleService startScan];
  39. }
  40. - (void)prepareViewDidLoad {
  41. //ble
  42. bleService = [BLEServiceHandler sharedManager];
  43. }
  44. -(void)startLoading:(BOOL)isStart {
  45. _lblTimer.hidden = !isStart;
  46. _imgvLoading.hidden = !isStart;
  47. if (isStart) {
  48. _elapsedSeconds = kMaxTimeOut;
  49. _lblTimer.text = [NSString stringWithFormat:@"%zd", _elapsedSeconds];
  50. if (!_timer) {
  51. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateInclusionStatus) userInfo:nil repeats:YES];
  52. }
  53. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  54. if ([_imgvLoading.layer animationForKey:@"SpinAnimation"] == nil) {
  55. CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  56. animation.fromValue = [NSNumber numberWithFloat:0.0f];
  57. animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
  58. animation.duration = 2.0f;
  59. animation.repeatCount = INFINITY;
  60. [_imgvLoading.layer addAnimation:animation forKey:@"SpinAnimation"];
  61. }
  62. });
  63. }
  64. else {
  65. _elapsedSeconds = kMaxTimeOut;
  66. if (_timer) {
  67. [_timer invalidate];
  68. _timer = nil;
  69. }
  70. if ([_imgvLoading.layer animationForKey:@"SpinAnimation"] != nil) {
  71. [_imgvLoading.layer removeAnimationForKey:@"SpinAnimation"];
  72. }
  73. }
  74. }
  75. - (void)updateInclusionStatus {
  76. dispatch_async(dispatch_get_main_queue(), ^(void) {
  77. _elapsedSeconds--;
  78. _lblTimer.text = [NSString stringWithFormat:@"%zd", _elapsedSeconds];
  79. // if (_elapsedSeconds == 0) {
  80. // [self finishDeviceDel:NO];
  81. // }
  82. });
  83. }
  84. #pragma mark - ble service delegate
  85. - (void)BLEEndScan:(NSMutableArray *)devices {
  86. [self startLoading:NO];
  87. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubSearchSuccessViewController" storyboardName:@"HomeHub"];
  88. if (devices.count == 0) {
  89. vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubSearchFailViaewController" storyboardName:@"HomeHub"];
  90. [self.navigationController pushViewController:vc animated:YES];
  91. return;
  92. }
  93. // else if(devices.count > 1) {
  94. //
  95. // [[JDFacade facade] alertTitle:@"Notice"
  96. // message:@"홈허브 인터넷 연결 설정은 한 개씩 진행하세요(준비 중인 홈허브가 두 개 이상일 경우 오류 처리됩니다.)"
  97. // completionHander:^{
  98. //
  99. // [self.navigationController popViewControllerAnimated:YES];
  100. // }];
  101. // return;
  102. // }
  103. [self.navigationController pushViewController:vc animated:NO];
  104. }
  105. - (void)BLEDisConnected:(BTLEDeivceModel *)info {
  106. [[JDFacade facade] toast:@"홈허브와 연결할 수 없습니다."];
  107. [self.navigationController popToRootViewControllerAnimated:YES];
  108. }
  109. #pragma mark - User Event
  110. - (IBAction)btnCloseTouched:(id)sender {
  111. [self.navigationController popToRootViewControllerAnimated:YES];
  112. }
  113. @end