| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //
- // HomeHubWifiSearchViewController.m
- // OneCable
- //
- // Created by nComz on 2017. 5. 11..
- // Copyright © 2017년 ntels. All rights reserved.
- //
- #import "HomeHubWifiSearchViewController.h"
- #import "HomeHubWifiSearchSuccessViewController.h"
- @interface HomeHubWifiSearchViewController (){
-
- BLEServiceHandler *bleService;
- NSTimer *_timer;
- NSInteger _elapsedSeconds;
- BOOL startScan;
-
- NSMutableDictionary *wifiData;
-
- }
- @end
- @implementation HomeHubWifiSearchViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self prepareViewDidLoad];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
-
- [self initUI];
- bleService.delegate = self;
- [bleService connect:bleService.conDevice];
- // if (!bleService.isConnected) {
- //
- //
- // }
- // else {
- // [self BLEConnected:nil];
- // }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- bleService.delegate = nil;
- }
- - (void)initUI {
-
- [self startLoading:YES];
- }
- - (void)prepareViewDidLoad {
-
-
- wifiData = [NSMutableDictionary new];
-
- //ble
- bleService = [BLEServiceHandler sharedManager];
- startScan = NO;
- }
- -(void)startLoading:(BOOL)isStart {
- _lblTimer.hidden = !isStart;
- _imgvLoading.hidden = !isStart;
-
- if (isStart) {
-
- _elapsedSeconds = kMaxTimeOut;
- _lblTimer.text = [NSString stringWithFormat:@"%zd", _elapsedSeconds];
- if (!_timer) {
- _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateInclusionStatus) userInfo:nil repeats:YES];
- }
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if ([_imgvLoading.layer animationForKey:@"SpinAnimation"] == nil) {
- CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- animation.fromValue = [NSNumber numberWithFloat:0.0f];
- animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
- animation.duration = 2.0f;
- animation.repeatCount = INFINITY;
- [_imgvLoading.layer addAnimation:animation forKey:@"SpinAnimation"];
- }
- });
- }
- else {
-
- _elapsedSeconds = kMaxTimeOut;
-
- if (_timer) {
- [_timer invalidate];
- _timer = nil;
- }
-
- if ([_imgvLoading.layer animationForKey:@"SpinAnimation"] != nil) {
- [_imgvLoading.layer removeAnimationForKey:@"SpinAnimation"];
- }
-
- }
-
- }
- - (void)updateInclusionStatus {
-
- dispatch_async(dispatch_get_main_queue(), ^(void) {
-
- _elapsedSeconds--;
- _lblTimer.text = [NSString stringWithFormat:@"%zd", _elapsedSeconds];
-
- if (startScan) {
-
- [bleService getWLanList:_elapsedSeconds%3];
- }
-
- if (_elapsedSeconds == 0) {
-
- if (wifiData.allKeys.count > 0) {
-
- [self moveHomeHubWifiSearchSuccess];
- }
- else {
-
- [self moveHomeHubWifiSearchFail];
- }
- }
- });
- }
- #pragma mark - User Event
- - (IBAction)btnCloseTouched:(id)sender {
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark - ble service delegate
- - (void)BLEConnected:(BTLEDeivceModel *)info {
-
- NSLog(@"home hub wifi search view connected!") ;
- startScan = YES ;
- [bleService scanWiFiList];
- }
- - (void)BLEDisConnected:(BTLEDeivceModel *)info {
-
- NSLog(@"home hub wifi search view disconnected!") ;
- }
- - (void)BLEWLanUpdateWithKey:(NSString *)kBLEChr result:(NSString *)result{
- BLEWLanListModel *response = [[BLEWLanListModel alloc] initWithString:result error:nil];
-
- if (response == nil) {
-
- return;
- }
- [wifiData setObject:response
- forKey:kBLEChr];
-
-
- if (wifiData.allKeys.count == 3) {
-
- [self moveHomeHubWifiSearchSuccess];
- }
-
- }
- - (void)moveHomeHubWifiSearchSuccess {
-
- [self startLoading:NO];
-
- NSArray *allKeys = wifiData.allKeys ;
- NSMutableArray *wifiList = [NSMutableArray new] ;
-
- for (NSString *key in allKeys) {
-
- BLEWLanListModel *modelList = [wifiData objectForKey:key] ;
-
- for (BLEWLanModel *model in modelList.wlan) {
-
- [wifiList addObject:model];
- }
- }
- HomeHubWifiSearchSuccessViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubWifiSearchSuccessViewController" storyboardName:@"HomeHub"];
- vc.wifiList = wifiList;
-
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)moveHomeHubWifiSearchFail {
- [self startLoading:NO];
-
- UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubWifiSearchFailViewController" storyboardName:@"HomeHub"];
-
- [self.navigationController pushViewController:vc animated:YES];
- }
- @end
|