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