// // ConAquarChooseWiFiVC.m // Ifish // // Created by wbzhan on 2019/9/20. // Copyright © 2019 lianlian. All rights reserved. // #import "ConAquarChooseWiFiVC.h" #import "ConnectingAquarVC.h" #import @interface ConAquarChooseWiFiVC () Strong UIImageView *topImage; Strong UIButton *connectWiFiBtn; Assign BOOL isGoChangeWiFi;//更换为设备的WiFi @end @implementation ConAquarChooseWiFiVC - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:Noti_WillEnterForeground object:nil]; } - (void)viewDidLoad { [super viewDidLoad]; [self addTitleViewWithTitle:@"选择设备WiFi"]; [self.view addSubview:self.topImage]; [self.view addSubview:self.connectWiFiBtn]; [self addContentLabel]; [self.topImage mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.mas_equalTo(self.view); make.height.mas_equalTo(kSizeFrom750(424)); }]; [self.connectWiFiBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.bottom.mas_equalTo(-30); make.width.mas_equalTo(200); make.height.mas_equalTo(30); }]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillEnterForeground:) name:Noti_WillEnterForeground object:nil]; // Do any additional setup after loading the view. } - (UIImageView *)topImage { if (!_topImage) { _topImage = InitObject(UIImageView); [_topImage setImage:IMAGEBYENAME(@"icons_con_topbg")]; if (self.deviceType==DEVICECAMERA) { [_topImage setImage:IMAGEBYENAME(@"apcoonetc")]; } } return _topImage; } - (UIButton *)connectWiFiBtn{ if (!_connectWiFiBtn) { _connectWiFiBtn = InitObject(UIButton); [_connectWiFiBtn setTitle:@"去设置WiFi" forState:UIControlStateNormal]; [_connectWiFiBtn setBackgroundColor:RGB(88, 151, 231)]; [_connectWiFiBtn setTitleColor:XWhite forState:UIControlStateNormal]; [_connectWiFiBtn.titleLabel setFont:FontSize(14)]; _connectWiFiBtn.layer.cornerRadius = kSizeFrom750(10); _connectWiFiBtn.layer.masksToBounds = YES; [_connectWiFiBtn addTarget:self action:@selector(connectWiFiBtnClick:) forControlEvents:UIControlEventTouchUpInside]; } return _connectWiFiBtn; } -(void)addContentLabel{ UILabel *preLabel; NSString*tip1=@"1.请将插排15秒内断电通电3次或长按复位键出现红灯快闪进入热点模式。"; NSString*tip2=@"2.点击去设置:设置-WiFi-选择ifish-xxx的网络,输入密码12345678,连接好后返回爱奇鱼app。"; if (self.deviceType==DEVICECAMERA) { tip1=@"1.请长按摄像头背后复位孔,复位摄像头,进入热点模式"; tip2=@"2.点击去设置:设置-WiFi-选择GW_AP_xxxx的网络,连接好后返回爱奇鱼app。"; } NSArray*textArr=@[tip1,tip2]; for (int i=0; i<2; i++) { UILabel *label = InitObject(UILabel); label.text = textArr[i]; label.textColor = RGB_92; label.font = FontSize(12); label.numberOfLines = 0; [self.view addSubview:label]; [label mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(kSizeFrom750(60)); make.right.mas_equalTo(-kSizeFrom750(60)); if (preLabel==nil) { make.top.mas_equalTo(self.topImage.mas_bottom).offset(kSizeFrom750(120)); } else { make.top.mas_equalTo(preLabel.mas_bottom).offset(kSizeFrom750(30)); } }]; preLabel = label; } } //跳转到WiFi设置页面 -(void)connectWiFiBtnClick:(UIButton *)sender{ NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if([[UIApplication sharedApplication] canOpenURL:url]) { if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; }else { [[UIApplication sharedApplication] openURL:url]; } self.isGoChangeWiFi = YES; } } -(void)checkWiFi{ [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) { NSString *wifiName = SSID; //先判断之前的wifi名称是否和热点的wifi名称重复,如果冲突,则提示wifi名称错误 if ([wifiName isEqualToString:self.wifiName]) { [self.view makeToast:@"请先连接设备热点"]; return; } //wifi正确,则尝试连接设备 if(self.deviceType==DEVICECAMERA) { YooseeNextConnectViewController *nextvc=[[YooseeNextConnectViewController alloc] init]; nextvc.wifiName=self.wifiName; nextvc.wifiPwd=self.wifiPwd; nextvc.conectType =conectType_ap; [self.navigationController pushViewController:nextvc animated:YES]; } else { ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC); connecting.ssid = self.ssid; connecting.bssid = self.bssid; connecting.wifiName = self.wifiName; connecting.wifiPassword = self.wifiPwd; connecting.deviceType=self.deviceType; [self.navigationController pushViewController:connecting animated:YES]; } }]; } //即将进入前台 -(void)viewWillEnterForeground:(NSNotification *)noti{ if (self.isGoChangeWiFi) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self checkWiFi]; }); } } /* #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