Authored by 盖剑秋

Fix bug .

... ... @@ -2,4 +2,70 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "YohoLive/Classes/YH_SocketService.m"
timestampString = "493980931.071469"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "342"
endingLineNumber = "342"
landmarkName = "-logout"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "YohoLive/Classes/YH_SocketService.m"
timestampString = "493980931.071469"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "347"
endingLineNumber = "347"
landmarkName = "-logout"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "YohoLive/Classes/YH_SocketService.m"
timestampString = "493980931.071469"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "350"
endingLineNumber = "350"
landmarkName = "-logout"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "YohoLive/Classes/YH_SocketService.m"
timestampString = "493980917.098365"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "200"
endingLineNumber = "200"
landmarkName = "-socket:didConnectToHost:port:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
... ...
... ... @@ -19,7 +19,7 @@
NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
NSMutableData *mutaData = [NSMutableData dataWithData:data];
[mutaData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// DLog(@"发送:%@",[[NSString alloc] initWithData:mutaData encoding:NSUTF8StringEncoding]);
DLog(@"发送:%@",[[NSString alloc] initWithData:mutaData encoding:NSUTF8StringEncoding]);
if (mutaData) {
[self writeData:mutaData withTimeout:SOCKET_LIVE_TIMEOUT tag:tag];
[self readDataWithTimeout:-1 tag:tag];
... ...
... ... @@ -103,26 +103,14 @@
//}
#pragma mark - Private Methods
- (void)_heartbeat{
// //TEST
// self.userName = [NSString stringWithFormat:@"%@",[NSDate date]];
// self.uid = [NSString stringWithFormat:@"%@",[NSDate date]];
// self.avartar = @"http://img02.yohoboys.com/contentimg/2016/06/16/15/021a29c892e7088fd7d96cbd41519da50d.jpg";
// [self sendMessage:@"21313"];
// [self userPraise];
- (void)heartbeat{
NSDictionary *params = @{@"cmd":@(SOCKET_TAG_HEARTBEAT),
@"msg":@"heart_ios",
@"room":MakeStringNotNil(self.room),
};
[_socket writeDataWithParams:params tag:SOCKET_TAG_SEND_MSG];
// [self loginToServer];
// [self listenData];
//心跳并判断是否已经断掉
[_socket writeDataWithParams:params tag:SOCKET_TAG_HEARTBEAT];
if (![_socket isConnected]) {
[self reConnect];
}
... ... @@ -130,6 +118,7 @@
if (!_hasLoginWithDevieToken) {
[self loginToServer];
}
[self performSelector:@selector(heartbeat) withObject:nil afterDelay:TimeIntervalForHeartBeat];
}
#pragma mark - Service
... ... @@ -207,7 +196,9 @@
};
[_socket writeDataWithParams:params tag:SOCKET_TAG_Start];
}
self.heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:TimeIntervalForHeartBeat target:self selector:@selector(_heartbeat) userInfo:nil repeats:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self heartbeat];
});
[self listenData];
}
... ... @@ -350,11 +341,13 @@
if (_heartBeatTimer) {
[_heartBeatTimer invalidate];
_heartBeatTimer = nil;
}
if (_connectTimer) {
[self.connectTimer invalidate];
self.connectTimer = nil;
}
[NSObject cancelPreviousPerformRequestsWithTarget:self];
_needSendStartPackage = YES;
[_socket disconnect];
}
... ...