temp
This commit is contained in:
parent
eb993bbe01
commit
ee03c2b4c8
|
|
@ -20,6 +20,10 @@
|
|||
@property (nonatomic, strong) MBProgressHUD *HUD;
|
||||
@property (nonatomic, assign) BOOL isDeleteingDevice;
|
||||
|
||||
@property (nonatomic, strong) NSTimer *deleteTimer;
|
||||
|
||||
@property (nonatomic, assign) NSInteger retryTimes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SettingResetViewController
|
||||
|
|
@ -37,29 +41,32 @@
|
|||
}
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = self;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand];
|
||||
|
||||
__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) {
|
||||
}
|
||||
|
||||
- (void)deleteNow {
|
||||
BOOL networkOk = NO;
|
||||
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (strongSelf.isDeleteingDevice) {
|
||||
return;
|
||||
}
|
||||
strongSelf.isDeleteingDevice = YES;
|
||||
[strongSelf deletDevice];
|
||||
}];
|
||||
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
||||
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (self.isDeleteingDevice) {
|
||||
return;
|
||||
}
|
||||
if (self.deleteTimer) {
|
||||
[self.deleteTimer invalidate];
|
||||
self.deleteTimer = nil;
|
||||
}
|
||||
self.isDeleteingDevice = YES;
|
||||
[self deletDevice];
|
||||
}
|
||||
|
||||
- (IBAction)tipBtnClicked:(id)sender {
|
||||
ConnectHotspotTipViewController *vc = [[ConnectHotspotTipViewController alloc] initWithNibName:nil bundle:nil];
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
|
|
@ -73,6 +80,7 @@
|
|||
[deviceArry enumerateObjectsUsingBlock:^(DeviceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj.macAddress isEqualToString:backModel.senderMacAddress]) {
|
||||
self.currentDevice = obj;
|
||||
self.deleteTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(deleteNow) userInfo:nil repeats:YES];
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
|
|
@ -112,6 +120,7 @@
|
|||
[[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
|
||||
}
|
||||
}
|
||||
self.retryTimes = 0;
|
||||
[self deleteDeviceRequset];
|
||||
}
|
||||
|
||||
|
|
@ -155,8 +164,13 @@
|
|||
}
|
||||
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
self.HUD.labelText = @"请求异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
if (self.retryTimes < 3) {
|
||||
[self deleteDeviceRequset];
|
||||
self.retryTimes += 1;
|
||||
} else {
|
||||
self.HUD.labelText = @"请求异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
+ (IFishHotpotUDPHelper *)sharedInstance;
|
||||
|
||||
@property (nonatomic,strong) NSTimer *loopTimer;
|
||||
|
||||
@property (nonatomic, weak) id<IFishHotpotUDPHelperDelegate> delegate;
|
||||
|
||||
- (void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
NSString *_pwd;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
@ -43,7 +44,6 @@
|
|||
UInt16 bindPort = 9954;
|
||||
|
||||
NSError *error;
|
||||
[self.clientSocket enableBroadcast:YES error:&error];
|
||||
//本地接收端口
|
||||
[self.clientSocket bindToPort:bindPort error:&error];
|
||||
[self.clientSocket receiveWithTimeout:-1 tag:0];
|
||||
|
|
@ -60,10 +60,10 @@
|
|||
|
||||
- (void)broadCastRestCommand {
|
||||
[self postmsg:@"命令已发出"];
|
||||
[self sendRestSocketData];
|
||||
[self sendResetSocketData];
|
||||
}
|
||||
|
||||
- (void)sendRestSocketData {
|
||||
- (void)sendResetSocketData {
|
||||
NSString* hostS = @"192.168.4.1";
|
||||
ResetDeviceModel *model = [ResetDeviceModel new];
|
||||
NSString *request=[NSString stringWithFormat:@"%@", model.description];
|
||||
|
|
@ -72,12 +72,12 @@
|
|||
|
||||
UInt16 port = 333;
|
||||
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
- (void)broadCastRestartCommand {
|
||||
[self postmsg:@"命令已发出"];
|
||||
[self sendRestSocketData];
|
||||
[self sendRestartSocketData];
|
||||
}
|
||||
|
||||
- (void)sendRestartSocketData {
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
|
||||
UInt16 port = 333;
|
||||
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
-(void)sendConnectHotspotSoketdata{
|
||||
|
|
@ -105,14 +105,11 @@
|
|||
NSData *data=[dataContorl stringToHexData:request];
|
||||
|
||||
UInt16 port = 333;
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
|
||||
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
|
||||
{
|
||||
[self.loopTimer invalidate];
|
||||
|
||||
NSString* result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
IFishUDPHelperBackMsgModel *model = [[IFishUDPHelperBackMsgModel alloc] initWithData:data];
|
||||
if ([model.result isEqualToString:@"01"]) {
|
||||
|
|
@ -128,9 +125,7 @@
|
|||
}
|
||||
|
||||
-(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{
|
||||
|
||||
[self.loopTimer invalidate];
|
||||
NSLog(@"关闭");
|
||||
NSLog(@"关闭");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -144,16 +139,12 @@
|
|||
|
||||
NSLog(@"dueToError%@",error);
|
||||
[self postmsg:error.localizedDescription];
|
||||
|
||||
[self.loopTimer invalidate];
|
||||
}
|
||||
|
||||
|
||||
-(void)dealloc{
|
||||
|
||||
[self.clientSocket close];
|
||||
[self.loopTimer invalidate];
|
||||
|
||||
}
|
||||
|
||||
- (void)postmsg:(NSString *)msg {
|
||||
|
|
|
|||
Loading…
Reference in New Issue