ifish/Ifish/controllers/IfishTabControllers/设备/IfishDeviceSelectList/IfishBindDeviceSelectViewCo...

272 lines
7.9 KiB
Objective-C

//
// IfishBindDeviceSelectViewController.m
// Ifish
//
// Created by imac on 2017/5/5.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "IfishBindDeviceSelectViewController.h"
#import "FishSelectDeviceListViewCell.h"
#import "P2PClient.h"
#import "UDPManager.h"
#import "YooseeNextConnectViewController.h"
#import "SecondConnectWifiController.h"
@interface IfishBindDeviceSelectViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property(nonatomic)BOOL islogInGewell;
@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];
[self loginGewell];
if( _islogInGewell){
NSLog(@"p2pConnect success.成功,你可以操作设备了");
}else{//new added
[self loginGewell];
NSLog(@"p2pConnect failure.失败,你将不能操作设备");
return;
}
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//CGPoint curentpoint= [self.cardScrollView contentOffsetWithIndex:[self.cardScrollView currentCard]];
//[self.cardScrollView.scrollView setContentOffset:curentpoint animated:NO];
[self loginGewell];
}
#pragma mark - loginGewell
-(void)loginGewell{
[[UDPManager sharedDefault] ScanLanDevice];
_islogInGewell = NO;
// LoginResult *loginResult = [UDManager getLoginInfo];
// NSString * P2PVerifyCode1 = @"1528438234";
// NSString * P2PVerifyCode2 = @"992805759";
// NSString *UserID = @"-2144354932";
UserModel *model=[dataContorl getUserInfo];
NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff];
NSLog(@"%@%@%@",userIDName,model.P2PVerifyCode1,model.P2PVerifyCode2);
if ([userIDName isEqualToString:@"0"]) {
//
[self.view makeToast:@"摄像头用户名空错误码10001"];
return;
}
if ([model.P2PVerifyCode1 isEqualToString:@""]) {
[self.view makeToast:@"摄像头P2PVerifyCode1空错误码10002"];
return;
}
if ([model.P2PVerifyCode2 isEqualToString:@""]) {
[self.view makeToast:@"摄像头P2PVerifyCode2空错误码10003"];
return;
}
_islogInGewell = [[P2PClient sharedClient] p2pConnectWithId:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2];
}
-(void)creatTab{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
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 3;
}
-(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 self.view.frame.size.width*0.698;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.1;
}
- (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;
}
if ( self.islogInGewell) {
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;
SecondConnectWifiController *wifivc=[[SecondConnectWifiController alloc]init];
[self.navigationController pushViewController:wifivc animated:YES];
}
break;
case 2:
{
//[self.view makeToast:@"敬请期待"];
}
break;
default:
break;
}
}else{
[self.view makeToast:@"请切换到WiFi环境下绑定"];
}
}
-(void)loginGewellWith:(UserModel *)model;
{
NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff];
if ([userIDName isEqualToString:@"0"]) {
[self.view makeToast:@"暂未检测到设备"];
return;
}
if ([model.P2PVerifyCode1 isEqualToString:@""]) {
[self.view makeToast:@"暂未检测到设备"];
return;
}
if ([model.P2PVerifyCode2 isEqualToString:@""]) {
[self.view makeToast:@"暂未检测到设备"];
return;
}
self.islogInGewell = [[P2PClient sharedClient] p2pConnectWithId:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2];
//loginResult.contactId 用户ID号
NSLog(@"%@%@%@",userIDName,model.P2PVerifyCode1,model.P2PVerifyCode2);
}
/*
#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