热点连接优化
This commit is contained in:
@@ -23,6 +23,7 @@ Strong ESPTouchTask* epTask;
|
||||
Strong NSMutableString *trackString;
|
||||
Strong MBProgressHUD *HUD;
|
||||
Strong NSTimer *timer;
|
||||
Strong UITapGestureRecognizer*tap;
|
||||
/**
|
||||
设备返回的mac地址
|
||||
*/
|
||||
@@ -44,7 +45,10 @@ Copy NSString *deviceId;
|
||||
[self addTitleViewWithTitle:@"尝试与设备建立连接"];
|
||||
|
||||
[self.view addSubview:self.progressView];
|
||||
|
||||
UITapGestureRecognizer*tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tryBindAgain:)];
|
||||
[self.progressView addGestureRecognizer:tap];
|
||||
self.tap=tap;
|
||||
self.tap.enabled=NO;
|
||||
[self.view addSubview:self.titleL];
|
||||
|
||||
[self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -194,8 +198,8 @@ Copy NSString *deviceId;
|
||||
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
if (self.retryTimes < 3) {
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
if (self.retryTimes < 10) {
|
||||
[self bindDeviceWithDeviceId:self.deviceId];
|
||||
self.retryTimes += 1;
|
||||
} else {
|
||||
[self endProgress];
|
||||
@@ -296,11 +300,7 @@ Copy NSString *deviceId;
|
||||
if (self.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
self.isBindingDevice = YES;
|
||||
if (self.bindTimer) {
|
||||
[self.bindTimer invalidate];
|
||||
self.bindTimer = nil;
|
||||
}
|
||||
|
||||
self.retryTimes = 0;
|
||||
if (self.deviceType==DEVICEPETS)
|
||||
{
|
||||
@@ -324,9 +324,9 @@ Copy NSString *deviceId;
|
||||
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
self.HUD.mode = MBProgressHUDModeIndeterminate;
|
||||
self.HUD.labelText = msg;
|
||||
if ([msg isEqualToString:@"Socket连接失败"])
|
||||
if ([msg containsString:@"Socket连接失败"])
|
||||
{
|
||||
[self.HUD hide:YES afterDelay:3];
|
||||
[self.HUD hide:YES afterDelay:5];
|
||||
[self endProgress];
|
||||
[self.progressView endProgressWithString:@"连接失败"];
|
||||
}
|
||||
@@ -392,8 +392,24 @@ Copy NSString *deviceId;
|
||||
|
||||
}
|
||||
#pragma mark - bind
|
||||
-(void)tryBindAgain:(UITapGestureRecognizer*)tap
|
||||
{
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
}
|
||||
-(void)bindDeviceWithSsid:(NSString*)bssid{
|
||||
NSLog(@"设备bssid_%@",bssid);
|
||||
if (self.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.isBindingDevice = YES;
|
||||
if (self.bindTimer) {
|
||||
[self.bindTimer invalidate];
|
||||
self.bindTimer = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[self appendTrakContent:@"=================进入绑定函数================="];
|
||||
NSString *userId = [dataContorl dataControlGetUserIdInfo];
|
||||
@@ -489,13 +505,21 @@ Copy NSString *deviceId;
|
||||
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
if (self.retryTimes < 6) {
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
self.retryTimes += 1;
|
||||
self.isBindingDevice=NO;
|
||||
if (self.retryTimes < 10) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
self.HUD.labelText = @"自动重连...";
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
|
||||
self.retryTimes += 1;
|
||||
|
||||
});
|
||||
} else {
|
||||
[self endProgress];
|
||||
[self endProgress];
|
||||
[self.progressView endProgressWithString:@"点击重试"];
|
||||
self.tap.enabled=YES;
|
||||
self.isBindingDevice = NO;
|
||||
self.HUD.labelText = @"请求异常";
|
||||
self.HUD.labelText = err.localizedDescription;
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
@@ -507,6 +531,7 @@ Copy NSString *deviceId;
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)appendTrakContent:(NSString *)msg {
|
||||
NSLog(@"msg=%@",msg);
|
||||
[self.trackString appendString:msg];
|
||||
[self.trackString appendString:@"\n"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user