socket未连接优化

This commit is contained in:
kai60 2022-03-29 11:34:55 +08:00
parent 90bcb3e43a
commit 64d5967585
4 changed files with 35 additions and 4 deletions

View File

@ -15869,7 +15869,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3; CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = WFX8GD5HFX; DEVELOPMENT_TEAM = WFX8GD5HFX;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
@ -15988,7 +15988,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3; CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = WFX8GD5HFX; DEVELOPMENT_TEAM = WFX8GD5HFX;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;

View File

@ -321,14 +321,28 @@ Copy NSString *deviceId;
{ {
return; return;
} }
[MBProgressHUD hideHUDForView:self.view animated:YES];
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
self.HUD.mode = MBProgressHUDModeIndeterminate; self.HUD.mode = MBProgressHUDModeIndeterminate;
self.HUD.labelText = msg; self.HUD.labelText = msg;
if ([msg containsString:@"Socket连接失败"]) if ([msg containsString:@"Socket连接失败"])
{ {
[self.HUD hide:YES afterDelay:5]; [self.HUD hide:YES afterDelay:3];
[self endProgress]; [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{ -(void)endProgress{

View File

@ -29,5 +29,6 @@
- (void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd; - (void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd;
- (void)broadCastRestartCommand; - (void)broadCastRestartCommand;
- (void)broadCastRestCommand; - (void)broadCastRestCommand;
-(void)closeComplete:(void(^)(void))block;
@end @end

View File

@ -24,6 +24,9 @@
@property (nonatomic, strong) NSTimer *loopTimer; @property (nonatomic, strong) NSTimer *loopTimer;
@property (nonatomic, assign) int tag; @property (nonatomic, assign) int tag;
@property (nonatomic, copy) void(^closeBlock)(void);
@end @end
@ -139,6 +142,16 @@
[self postmsg:@"发送失败"]; [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 -(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{ {
@ -161,6 +174,9 @@
-(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{ -(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{
[self postmsg:@"连接关闭"]; [self postmsg:@"连接关闭"];
if (self.closeBlock) {
self.closeBlock();
}
} }