temp
This commit is contained in:
@@ -39,6 +39,10 @@
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL isBindingDevice;
|
||||
|
||||
@property (nonatomic, strong) NSTimer *bindTimer;
|
||||
|
||||
@property (nonatomic, assign) NSInteger retryTimes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ConnectHotpotViewController
|
||||
@@ -166,33 +170,37 @@
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"答复Mac地址:%@", backModel.senderMacAddress]];
|
||||
self.macAddress = backModel.senderMacAddress;
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
BOOL networkOk = NO;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
if (![[strongSelf currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
networkOk = YES;
|
||||
}
|
||||
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (strongSelf.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
if (strongSelf.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
strongSelf.isBindingDevice = YES;
|
||||
[strongSelf bindDeviceWithSsid:self.macAddress];
|
||||
}];
|
||||
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
||||
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = nil;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand];
|
||||
self.bindTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startBinding) userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)startBinding {
|
||||
BOOL networkOk = NO;
|
||||
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
networkOk = YES;
|
||||
}
|
||||
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (self.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
if (self.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
self.isBindingDevice = YES;
|
||||
if (self.bindTimer) {
|
||||
[self.bindTimer invalidate];
|
||||
self.bindTimer = nil;
|
||||
}
|
||||
self.retryTimes = 0;
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
}
|
||||
|
||||
- (void)udpHelperMessage:(NSString *)msg {
|
||||
@@ -267,12 +275,16 @@
|
||||
|
||||
|
||||
} failure:^(NSError *err) {
|
||||
self.isBindingDevice = NO;
|
||||
self.HUD.labelText = @"网络异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
|
||||
if (self.retryTimes < 3) {
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
self.retryTimes += 1;
|
||||
} else {
|
||||
self.isBindingDevice = NO;
|
||||
self.HUD.labelText = @"请求异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user