// // IfishBindDeviceSelectViewController.m // Ifish // // Created by imac on 2017/5/5. // Copyright © 2017年 lianlian. All rights reserved. // #import "IfishBindDeviceSelectViewController.h" #import "FishSelectDeviceListViewCell.h" #import #import "UDPManager.h" #import "YooseeNextConnectViewController.h" #import "SecondConnectWifiController.h" #import "IfishHotBarVc.h" #import "HitbarWifeVc.h" #import "SVProgressHUD.h" #import "ConAquarMethodVC.h" #import "ConfigWifiViewController.h" @interface IfishBindDeviceSelectViewController () @property (nonatomic,strong) UITableView *tableView; @end extern BOOL isfromCameraView; @implementation IfishBindDeviceSelectViewController - (void)viewDidLoad { [super viewDidLoad]; isfromCameraView = NO; // Do any additional setup after loading the view. [self addTitleViewWithTitle:@"选择设备"]; [self creatTab]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; } #pragma mark - loginGWP2P -(void)loginGWP2P{ [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack]; [[UDPManager sharedDefault] ScanLanDevice]; UserModel *model=[dataContorl getUserInfo]; NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff]; NSLog(@"%@%@%@",userIDName,model.P2PVerifyCode1,model.P2PVerifyCode2); // dispatch_queue_t queue = dispatch_queue_create("net.bujige.testQueue", DISPATCH_QUEUE_CONCURRENT); // dispatch_async(queue, ^{ // // 追加任务1 if ([GWP2PClient sharedClient].linkStatus!=P2PLinkStatusOK) { [[GWP2PClient sharedClient] connectWithAccount:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2 sessionID1:model.sessionID sessionID2:model.sessionID2 customerIDs:nil]; } // dispatch_async(dispatch_get_main_queue(), ^{ [SVProgressHUD dismiss]; // }); // }); } -(void)creatTab{ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,kScreenWidth,kScreenHeight-TOP_HEIGHT) style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.estimatedRowHeight = 0; self.tableView.estimatedSectionFooterHeight = 0; self.tableView.estimatedSectionHeaderHeight = 0; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:self.tableView]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 5; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ FishSelectDeviceListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FishSelectDeviceListViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"FishSelectDeviceListViewCell" owner:self options:nil] lastObject]; } [cell initCellImgsAt:indexPath]; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 278/2.0; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ Reachability *currReach = [Reachability reachabilityForLocalWiFi]; NetworkStatus status = [currReach currentReachabilityStatus]; NSLog(@"NetworkStatus%ld", (long)status); if (status==AFNetworkReachabilityStatusReachableViaWiFi) { //wifi环境下转跳下一界面 switch (indexPath.row) { case 0: { //摄像头 NSArray * cameraArr =[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"]; // if ([cameraArr count]>=5) { // [self.view makeToast:@"设备已达上限"]; // return; // } [self loginGWP2P]; if ( [GWP2PClient sharedClient].linkStatus==P2PLinkStatusOK) { self.hidesBottomBarWhenPushed = YES; ConAquarMethodVC *methodVC = InitObject(ConAquarMethodVC); methodVC.deviceType=DEVICECAMERA; methodVC.titleString=@"连接摄像头"; [self.navigationController pushViewController:methodVC animated:YES]; // self.hidesBottomBarWhenPushed = YES; // YooseeNextConnectViewController *nextvc=[[YooseeNextConnectViewController alloc] init]; // [self.navigationController pushViewController:nextvc animated:YES]; // nextvc.conectType = 0; }else{ UserModel *model=[dataContorl getUserInfo]; [self loginGewellWith:model]; } } break; case 1: { //水族箱 NSArray * deviceArr =[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; // if ([deviceArr count]>=5) { // // [self.view makeToast:@"设备已达上限"]; // return; // // } self.hidesBottomBarWhenPushed = YES; ConfigWifiViewController *methodVC = [[ConfigWifiViewController alloc]init]; methodVC.deviceType=DEVICEAQUARIUM; // SecondConnectWifiController *wifivc=[[SecondConnectWifiController alloc]init]; // wifivc.vcTitle=@"连接水族箱"; methodVC.titleString=@"连接水族箱"; [self.navigationController pushViewController:methodVC animated:YES]; } break; case 2: { self.hidesBottomBarWhenPushed = YES; ConfigWifiViewController *methodVC = [[ConfigWifiViewController alloc]init]; methodVC.deviceType=DEVICEHEATING; methodVC.titleString=@"连接加热器"; [self.navigationController pushViewController:methodVC animated:YES]; // SecondConnectWifiController *wifivc=[[SecondConnectWifiController alloc]init]; // wifivc.vcTitle=@"连接加热器"; // [self.navigationController pushViewController:wifivc animated:YES]; // [wifivc addTitleViewWithTitle:@"连接加热器"]; //[self.view makeToast:@"敬请期待"]; 加热棒 } break; case 3: { self.hidesBottomBarWhenPushed = YES; ConfigWifiViewController *methodVC = [[ConfigWifiViewController alloc]init]; methodVC.deviceType=DEVICEPETS; methodVC.titleString=@"连接宠物笼"; [self.navigationController pushViewController:methodVC animated:YES]; // SecondConnectWifiController *wifivc=[[SecondConnectWifiController alloc]init]; // wifivc.vcTitle=@"连接加热器"; // [self.navigationController pushViewController:wifivc animated:YES]; // [wifivc addTitleViewWithTitle:@"连接加热器"]; //[self.view makeToast:@"敬请期待"]; 加热棒 } break; default: break; } }else{ [self.view makeToast:@"请切换到WiFi环境下绑定"]; } } -(void)loginGewellWith:(UserModel *)model { NSString *accountId =[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff]; if ([accountId isEqualToString:@"0"]) { [self.view makeToast:@"暂未检测到设备"]; return; } if ([model.P2PVerifyCode1 isEqualToString:@""]) { [self.view makeToast:@"暂未检测到设备"]; return; } if ([model.P2PVerifyCode2 isEqualToString:@""]) { [self.view makeToast:@"暂未检测到设备"]; return; } if ([GWP2PClient sharedClient]!=P2PLinkStatusOK) { [[GWP2PClient sharedClient] connectWithAccount:accountId codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2 sessionID1:model.sessionID sessionID2:model.sessionID2 customerIDs:nil]; } //loginResult.contactId 用户ID号 NSLog(@"%@%@%@",accountId,model.P2PVerifyCode1,model.P2PVerifyCode2,model.sessionID,model.sessionID2); } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end