热点连接部分bug修复

This commit is contained in:
wbzhan
2019-10-09 18:09:02 +08:00
parent bfdf208899
commit 7157c3b0ed
13 changed files with 110 additions and 62 deletions
@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface ConAquarChooseWiFiVC : BaseViewController
Copy NSString *wifiName;
Copy NSString *wifiPwd;
Copy NSString *ssid;
Copy NSString *bssid;
@end
NS_ASSUME_NONNULL_END
@@ -105,13 +105,14 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) {
//wifi正确,则尝试连接设备
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
connecting.ssid = self.ssid;
connecting.bssid = self.bssid;
connecting.wifiName = self.wifiName;
connecting.wifiPassword = self.wifiPwd;
[self.navigationController pushViewController:connecting animated:YES];
}else{
[self.view makeToast:@"WiFi名称不匹配,请重试"];
}
}
- (id)getSSIDInfo
{
@@ -44,8 +44,8 @@ Strong UIButton *nextBtn;
[self loadLayout];
NSDictionary *ifs = [self getSSIDInfo];
self.wifiNameTextField.text = [ifs objectForKey:@"SSID"];
[self getSSid];//获取Wifi信息
// Do any additional setup after loading the view.
}
@@ -96,13 +96,9 @@ Strong UIButton *nextBtn;
_wifiNameTextField.leftViewMode = UITextFieldViewModeAlways;
UIView *leftView = InitObject(UIView);
leftView.frame = RECT(0, 0, kSizeFrom750(90), kSizeFrom750(90));
UIImageView *leftImage = [[UIImageView alloc] init];
UIImageView *leftImage = [[UIImageView alloc] initWithFrame:RECT(kSizeFrom750(20), kSizeFrom750(20), kSizeFrom750(50), kSizeFrom750(50))];
[leftView addSubview:leftImage];
[leftImage setImage:IMAGEBYENAME(@"icons_con_wifi")];
[leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(leftView);
make.width.height.mas_equalTo(kSizeFrom750(50));
}];
_wifiNameTextField.leftView = leftView;
}
@@ -122,13 +118,9 @@ Strong UIButton *nextBtn;
_wifiPwdTextField.leftViewMode = UITextFieldViewModeAlways;
UIView *leftView = InitObject(UIView);
leftView.frame = RECT(0, 0, kSizeFrom750(90), kSizeFrom750(90));
UIImageView *leftImage = [[UIImageView alloc] init];
UIImageView *leftImage = [[UIImageView alloc] initWithFrame:RECT(kSizeFrom750(15), kSizeFrom750(15), kSizeFrom750(60), kSizeFrom750(60))];
[leftView addSubview:leftImage];
[leftImage setImage:IMAGEBYENAME(@"icons_con_lock")];
[leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(leftView);
make.width.height.mas_equalTo(kSizeFrom750(60));
}];
_wifiPwdTextField.leftView = leftView;
}
return _wifiPwdTextField;
@@ -189,6 +181,35 @@ Strong UIButton *nextBtn;
preLabel = label;
}
}
-(void)getSSid{
Reachability *currReach = [Reachability reachabilityForLocalWiFi];
NetworkStatus status = [currReach currentReachabilityStatus];
NSLog(@"%ld", (long)status);
if (status==AFNetworkReachabilityStatusReachableViaWiFi) {
[self connectMyWIFI];
}else{
[self showTitle:@"" messsage:@"请切换到WiFi环境下绑定"];
}
}
-(void)connectMyWIFI{
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
NSDictionary *netInfo = [self getSSIDInfo];
_ssid = [netInfo objectForKey:@"SSID"];
_bssid = [netInfo objectForKey:@"BSSID"];
self.wifiPwdTextField.text=pass;
self.wifiNameTextField.text = [netInfo objectForKey:@"SSID"];
}
// refer to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library
//获取WiFi信息
- (id)getSSIDInfo
{
@@ -213,9 +234,13 @@ Strong UIButton *nextBtn;
[self.view makeToast:@"路由器密码不能包含特殊字符,只能为数字、字母或下划线"];
return;
}
[self.wifiPwdTextField resignFirstResponder];
[self.wifiNameTextField resignFirstResponder];
ConAquarChooseWiFiVC *chooseVC = InitObject(ConAquarChooseWiFiVC);
chooseVC.wifiName = self.wifiNameTextField.text;
chooseVC.wifiPwd = self.wifiPwdTextField.text;
chooseVC.wifiName = [NSString stringWithFormat:@"%@",self.wifiNameTextField.text];
chooseVC.wifiPwd = [NSString stringWithFormat:@"%@",self.wifiPwdTextField.text];
chooseVC.ssid = [NSString stringWithFormat:@"%@",self.ssid];
chooseVC.bssid = [NSString stringWithFormat:@"%@",self.bssid];
[self.navigationController pushViewController:chooseVC animated:YES];
}
/*
@@ -51,6 +51,7 @@ Assign NSInteger retryTimes;
make.width.mas_equalTo(kSizeFrom750(700));
}];
[self.progressView updatePercent:100 animation:YES];
[self.progressView endProgressWithString:@"设备连接中..."];
//AP模式配网
// [[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) {
// //
@@ -59,12 +60,14 @@ Assign NSInteger retryTimes;
// //成功
// }];
//传入设备要连接的wifi名称和密码
// [self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword];
[self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword];
// Do any additional setup after loading the view.
self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)dealloc
{
if (!self.timer) {
@@ -165,7 +168,11 @@ Assign NSInteger retryTimes;
self.HUD.mode = MBProgressHUDModeIndeterminate;
self.HUD.labelText = msg;
}
-(void)endProgress{
[self.progressView endProgressWithString:@"连接结束"];
[self.timer invalidate];
self.timer = nil;
}
#pragma mark - bind
-(void)bindDeviceWithSsid:(NSString*)bssid{
NSLog(@"设备bssid_%@",bssid);
@@ -178,14 +185,12 @@ Assign NSInteger retryTimes;
[self.progressView endEditing:YES];
self.isBindingDevice = NO;
self.macAddress = nil;
[self.progressView endProgressWithString:@"连接结束"];
[self.timer invalidate];
self.timer = nil;
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSLog(@"data:%@",resultDic[@"data"]);
[self appendTrakContent:[NSString stringWithFormat:@"绑定请求成功。返回数据为:%@", resultDic]];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
[self endProgress];
// 保存设备信息
NSDictionary*dataDic=resultDic[@"data"];
DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:dataDic];
@@ -241,6 +246,7 @@ Assign NSInteger retryTimes;
[self bindDeviceWithSsid:self.macAddress];
self.retryTimes += 1;
} else {
[self endProgress];
self.isBindingDevice = NO;
self.HUD.labelText = @"请求异常";
[self.HUD hide:YES afterDelay:2];