| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- //
- // HomeHubWifiSearchSuccessViewController.m
- // OneCable
- //
- // Created by nComz on 2017. 5. 11..
- // Copyright © 2017년 ntels. All rights reserved.
- //
- #import "HomeHubWifiSearchSuccessViewController.h"
- #import "HomeHubWifiPasswdInputViewController.h"
- @interface HomeHubWifiSearchSuccessViewController () <CustomCheckBoxDelegate> {
- BLEServiceHandler *bleService;
- BLEWLanModel *selectedWLanModel;
-
-
- //비밀번호 없는 경우
-
- BOOL updateSSID;
- BOOL updateBSSID;
- BOOL updateIPSet;
- BOOL updateIPAddr;
-
- NSTimer *_timer;
- NSInteger _elapsedSeconds;
-
- }
- @end
- @implementation HomeHubWifiSearchTableViewCell
- @end
- @implementation HomeHubWifiSearchSuccessViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- bleService.delegate = self;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- bleService.delegate = nil;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)initUI {
-
- _imgvLoading.hidden = YES;
- _btnNext.enabled = NO;
-
- [self initTableViewAsDefaultStyle:_tableView];
- }
- - (void)prepareViewDidLoad {
-
- //ble
- bleService = [BLEServiceHandler sharedManager];
-
- updateSSID = updateBSSID = updateIPSet = updateIPAddr = NO;
-
- [_tableView reloadData];
- }
- -(void)startLoading:(BOOL)isStart {
-
- _imgvLoading.hidden = !isStart;
-
- if (isStart) {
-
- _elapsedSeconds = kMaxTimeOut;
-
- 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--;
-
- if (_elapsedSeconds == 0) {
-
- [self startLoading:NO];
- }
- });
- }
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- return _wifiList.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- return 101.0f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- HomeHubWifiSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WifiSearchCellIdentifier"];
-
- BLEWLanModel *model = [_wifiList objectAtIndex:indexPath.row];
-
- cell.lblHubName.text = model.ssid;
- cell.chkBtn.selected = [selectedWLanModel isEqual:model];
- cell.imgvWifi.highlighted = !EQUALS(model.security, @"none");
-
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- [super tableView:tableView didSelectRowAtIndexPath:indexPath];
-
- BLEWLanModel *model = [_wifiList objectAtIndex:indexPath.row];
- selectedWLanModel = model;
- _btnNext.enabled = YES;
- [_tableView reloadData];
- }
- //#pragma mark - CustomCheckBox Delegate {
- //- (void)didCheckBoxClicked:(id)sender {
- //
- // CustomCheckBox *btn = sender;
- // btn.selected = !btn.selected;
- //
- // selectedWLanModel = btn.value;
- // _btnNext.enabled = YES;
- //
- // [_tableView reloadData];
- //
- //}
- #pragma mark - user Event
- - (IBAction)btnCancelTouched:(id)sender {
-
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- - (IBAction)btnNextTouched:(id)sender {
-
- NSLog(@"selectedWLanModel : %@", selectedWLanModel);
-
- if (selectedWLanModel != nil) {
-
- [bleService setWiFiSSID:selectedWLanModel.ssid];
- [bleService readAndNotifyCharacteristicUUID:kBLEChrStSSIDArg
- isNotify:NO];
- }
- }
- #pragma mark - ble delegate
- - (void)BLEWiFiSSIDUpdate:(NSString*)ssid {
-
- NSLog(@"\nwifi search seccess BLEWiFiSSIDUpdate ssid : %@", selectedWLanModel.ssid);
- NSLog(@"ssid : %@", ssid);
-
- if (EQUALS(selectedWLanModel.ssid, ssid)) {
-
- if (EQUALS(selectedWLanModel.security, @"none")) {
-
- [self startLoading:YES];
- [bleService setWiFiPwd:@""];
- [bleService enableDHCP];
- [bleService readAndNotifyCharacteristicUUID:kBLEChrStDHCPArg isNotify:NO];
-
- updateSSID = updateBSSID = updateIPSet = updateIPAddr = NO;
- }
- else {
-
- HomeHubWifiPasswdInputViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubWifiPasswdInputViewController" storyboardName:@"HomeHub"];
- vc.selectedWLanModel = selectedWLanModel;
-
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- else {
-
- //실패처리
- [[JDFacade facade] alertTitle:@"인터넷 연결 설정 실패"
- message:@"인터넷 연결 설정에 실패하였습니다."];
-
- }
- }
- //enableDHCP
- - (void)BLEWiFiDHCPUpdate:(id)data {
-
- NSLog(@"\nwifi search seccess BLEWiFiDHCPUpdate!");
-
- [bleService applyWiFiSettingInfo];
- [self performSelector:@selector(afterApplyNotifyConnect) withObject:nil afterDelay:0.5];
-
- }
- - (void)afterApplyNotifyConnect {
-
- NSLog(@"\nafterApplyNotifyConnect!");
- [bleService readAndNotifyCharacteristicUUID:kBLEChrRdConInfo isNotify:YES];
- }
- //kBLEChrRdConInfo
- - (void)BLEWiFiConnectionUpdate:(CBCharacteristic *)info {
-
- NSLog(@"\nwifi search seccess BLEWiFiConnectionUpdate!");
-
- NSString *value = [bleService hexStringValue:info] ;
-
- if (value.length > 0 &&
- EQUALS([value substringFromIndex:value.length-1], @"1")) {
-
- [bleService readConnectionWiFiInfo];
- }
- else if (value.length > 0 &&
- EQUALS([value substringFromIndex:value.length-1], @"0")) {
-
- //실패
- [self startLoading:NO];
- [[JDFacade facade] alert:@"네트워크 연결에 실패하였습니다." completionHander:^{
-
- [self.navigationController popViewControllerAnimated:NO];
- }];
- }
- }
- //readConnectionWiFiInfo
- - (void)BLEWiFiConnectionInfoUpdateWithKey:(NSString *)kBLEChr
- result:(NSString *)result {
-
- NSLog(@"\nwifi search seccess BLEWiFiConnectionInfoUpdateWithKey") ;
-
- if (EQUALS(kBLEChr, kBLEChrRdSSID)) {
- updateSSID = YES;
- }
- else if(EQUALS(kBLEChr, kBLEChrRdBSSID)) {
- updateBSSID = YES;
- }
- else if(EQUALS(kBLEChr, kBLEChrRnIpSet)) {
- updateIPSet = YES;
- }
- else if(EQUALS(kBLEChr, kBLEChrRnIpAddr)) {
- updateIPAddr = YES;
- }
-
- // 연결 확인 완료
- if (updateSSID && updateBSSID && updateIPSet && updateIPAddr) {
-
- [self startLoading:NO];
-
- UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubUpdateCompleteViewController" storyboardName:@"HomeHub"];
-
- [self.navigationController pushViewController:vc animated:YES];
-
- }
- }
- - (void)BLEDisConnected:(BTLEDeivceModel *)info {
-
- [[JDFacade facade] toast:@"블루투스 연결이 끊어졌습니다."];
- [self.navigationController popToRootViewControllerAnimated:YES];
-
- }
- @end
|