From 64d5967585d7a168c7f65cf97b0c0f91b191626d Mon Sep 17 00:00:00 2001 From: kai60 Date: Tue, 29 Mar 2022 11:34:55 +0800 Subject: [PATCH] =?UTF-8?q?socket=E6=9C=AA=E8=BF=9E=E6=8E=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ifish.xcodeproj/project.pbxproj | 4 ++-- .../ConnectAauariumVC/ConnectingAquarVC.m | 18 ++++++++++++++++-- .../leftcontrollers/IFishHotpotUDPHelper.h | 1 + .../leftcontrollers/IFishHotpotUDPHelper.m | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Ifish.xcodeproj/project.pbxproj b/Ifish.xcodeproj/project.pbxproj index f759c29..16999e9 100644 --- a/Ifish.xcodeproj/project.pbxproj +++ b/Ifish.xcodeproj/project.pbxproj @@ -15869,7 +15869,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = WFX8GD5HFX; ENABLE_BITCODE = NO; ENABLE_TESTABILITY = YES; @@ -15988,7 +15988,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = WFX8GD5HFX; ENABLE_BITCODE = NO; ENABLE_TESTABILITY = YES; diff --git a/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m b/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m index 374ac14..9b921f8 100644 --- a/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m +++ b/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m @@ -321,14 +321,28 @@ Copy NSString *deviceId; { return; } + [MBProgressHUD hideHUDForView:self.view animated:YES]; self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; self.HUD.mode = MBProgressHUDModeIndeterminate; self.HUD.labelText = msg; if ([msg containsString:@"Socket连接失败"]) { - [self.HUD hide:YES afterDelay:5]; + [self.HUD hide:YES afterDelay:3]; [self endProgress]; - [self.progressView endProgressWithString:@"连接失败"]; + if (self.retryTimes<10) + { + self.retryTimes++; + [self.progressView endProgressWithString:@"自动重试..."]; + WEAK_SELF; + [[IFishHotpotUDPHelper sharedInstance] closeComplete:^{ + [weakSelf sendToDeviceWithSSIDName:weakSelf.wifiName andSSIDPWD:weakSelf.wifiPassword]; + }]; + } + else + { + [self.progressView endProgressWithString:@"连接结束"]; + } + } } -(void)endProgress{ diff --git a/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.h b/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.h index fdbdaeb..aea9a79 100644 --- a/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.h +++ b/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.h @@ -29,5 +29,6 @@ - (void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd; - (void)broadCastRestartCommand; - (void)broadCastRestCommand; +-(void)closeComplete:(void(^)(void))block; @end diff --git a/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m b/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m index abc2df9..318c40e 100644 --- a/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m +++ b/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m @@ -24,6 +24,9 @@ @property (nonatomic, strong) NSTimer *loopTimer; @property (nonatomic, assign) int tag; +@property (nonatomic, copy) void(^closeBlock)(void); + + @end @@ -139,6 +142,16 @@ [self postmsg:@"发送失败"]; } } +- (void)closeComplete:(void (^)(void))block +{ + self.closeBlock = block; + if(self.loopTimer) + { + [self.loopTimer invalidate]; + self.loopTimer=nil; + } + [self.clientSocket close]; +} -(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port { @@ -161,6 +174,9 @@ -(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{ [self postmsg:@"连接关闭"]; + if (self.closeBlock) { + self.closeBlock(); + } }