Authored by 盖剑秋

Fix bug .

@@ -2,4 +2,70 @@ @@ -2,4 +2,70 @@
2 <Bucket 2 <Bucket
3 type = "0" 3 type = "0"
4 version = "2.0"> 4 version = "2.0">
  5 + <Breakpoints>
  6 + <BreakpointProxy
  7 + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
  8 + <BreakpointContent
  9 + shouldBeEnabled = "Yes"
  10 + ignoreCount = "0"
  11 + continueAfterRunningActions = "No"
  12 + filePath = "YohoLive/Classes/YH_SocketService.m"
  13 + timestampString = "493980931.071469"
  14 + startingColumnNumber = "9223372036854775807"
  15 + endingColumnNumber = "9223372036854775807"
  16 + startingLineNumber = "342"
  17 + endingLineNumber = "342"
  18 + landmarkName = "-logout"
  19 + landmarkType = "5">
  20 + </BreakpointContent>
  21 + </BreakpointProxy>
  22 + <BreakpointProxy
  23 + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
  24 + <BreakpointContent
  25 + shouldBeEnabled = "Yes"
  26 + ignoreCount = "0"
  27 + continueAfterRunningActions = "No"
  28 + filePath = "YohoLive/Classes/YH_SocketService.m"
  29 + timestampString = "493980931.071469"
  30 + startingColumnNumber = "9223372036854775807"
  31 + endingColumnNumber = "9223372036854775807"
  32 + startingLineNumber = "347"
  33 + endingLineNumber = "347"
  34 + landmarkName = "-logout"
  35 + landmarkType = "5">
  36 + </BreakpointContent>
  37 + </BreakpointProxy>
  38 + <BreakpointProxy
  39 + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
  40 + <BreakpointContent
  41 + shouldBeEnabled = "Yes"
  42 + ignoreCount = "0"
  43 + continueAfterRunningActions = "No"
  44 + filePath = "YohoLive/Classes/YH_SocketService.m"
  45 + timestampString = "493980931.071469"
  46 + startingColumnNumber = "9223372036854775807"
  47 + endingColumnNumber = "9223372036854775807"
  48 + startingLineNumber = "350"
  49 + endingLineNumber = "350"
  50 + landmarkName = "-logout"
  51 + landmarkType = "5">
  52 + </BreakpointContent>
  53 + </BreakpointProxy>
  54 + <BreakpointProxy
  55 + BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
  56 + <BreakpointContent
  57 + shouldBeEnabled = "Yes"
  58 + ignoreCount = "0"
  59 + continueAfterRunningActions = "No"
  60 + filePath = "YohoLive/Classes/YH_SocketService.m"
  61 + timestampString = "493980917.098365"
  62 + startingColumnNumber = "9223372036854775807"
  63 + endingColumnNumber = "9223372036854775807"
  64 + startingLineNumber = "200"
  65 + endingLineNumber = "200"
  66 + landmarkName = "-socket:didConnectToHost:port:"
  67 + landmarkType = "5">
  68 + </BreakpointContent>
  69 + </BreakpointProxy>
  70 + </Breakpoints>
5 </Bucket> 71 </Bucket>
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error]; 19 NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
20 NSMutableData *mutaData = [NSMutableData dataWithData:data]; 20 NSMutableData *mutaData = [NSMutableData dataWithData:data];
21 [mutaData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 21 [mutaData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
22 -// DLog(@"发送:%@",[[NSString alloc] initWithData:mutaData encoding:NSUTF8StringEncoding]); 22 + DLog(@"发送:%@",[[NSString alloc] initWithData:mutaData encoding:NSUTF8StringEncoding]);
23 if (mutaData) { 23 if (mutaData) {
24 [self writeData:mutaData withTimeout:SOCKET_LIVE_TIMEOUT tag:tag]; 24 [self writeData:mutaData withTimeout:SOCKET_LIVE_TIMEOUT tag:tag];
25 [self readDataWithTimeout:-1 tag:tag]; 25 [self readDataWithTimeout:-1 tag:tag];
@@ -103,26 +103,14 @@ @@ -103,26 +103,14 @@
103 //} 103 //}
104 104
105 #pragma mark - Private Methods 105 #pragma mark - Private Methods
106 -- (void)_heartbeat{  
107 -  
108 -  
109 -// //TEST  
110 -// self.userName = [NSString stringWithFormat:@"%@",[NSDate date]];  
111 -// self.uid = [NSString stringWithFormat:@"%@",[NSDate date]];  
112 -// self.avartar = @"http://img02.yohoboys.com/contentimg/2016/06/16/15/021a29c892e7088fd7d96cbd41519da50d.jpg";  
113 -// [self sendMessage:@"21313"];  
114 -// [self userPraise];  
115 - 106 +- (void)heartbeat{
116 107
117 NSDictionary *params = @{@"cmd":@(SOCKET_TAG_HEARTBEAT), 108 NSDictionary *params = @{@"cmd":@(SOCKET_TAG_HEARTBEAT),
118 @"msg":@"heart_ios", 109 @"msg":@"heart_ios",
119 @"room":MakeStringNotNil(self.room), 110 @"room":MakeStringNotNil(self.room),
120 }; 111 };
121 - [_socket writeDataWithParams:params tag:SOCKET_TAG_SEND_MSG]; 112 + [_socket writeDataWithParams:params tag:SOCKET_TAG_HEARTBEAT];
122 113
123 -// [self loginToServer];  
124 -// [self listenData];  
125 - //心跳并判断是否已经断掉  
126 if (![_socket isConnected]) { 114 if (![_socket isConnected]) {
127 [self reConnect]; 115 [self reConnect];
128 } 116 }
@@ -130,6 +118,7 @@ @@ -130,6 +118,7 @@
130 if (!_hasLoginWithDevieToken) { 118 if (!_hasLoginWithDevieToken) {
131 [self loginToServer]; 119 [self loginToServer];
132 } 120 }
  121 + [self performSelector:@selector(heartbeat) withObject:nil afterDelay:TimeIntervalForHeartBeat];
133 } 122 }
134 123
135 #pragma mark - Service 124 #pragma mark - Service
@@ -207,7 +196,9 @@ @@ -207,7 +196,9 @@
207 }; 196 };
208 [_socket writeDataWithParams:params tag:SOCKET_TAG_Start]; 197 [_socket writeDataWithParams:params tag:SOCKET_TAG_Start];
209 } 198 }
210 - self.heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:TimeIntervalForHeartBeat target:self selector:@selector(_heartbeat) userInfo:nil repeats:YES]; 199 + dispatch_async(dispatch_get_main_queue(), ^{
  200 + [self heartbeat];
  201 + });
211 [self listenData]; 202 [self listenData];
212 } 203 }
213 204
@@ -350,11 +341,13 @@ @@ -350,11 +341,13 @@
350 if (_heartBeatTimer) { 341 if (_heartBeatTimer) {
351 [_heartBeatTimer invalidate]; 342 [_heartBeatTimer invalidate];
352 _heartBeatTimer = nil; 343 _heartBeatTimer = nil;
  344 +
353 } 345 }
354 if (_connectTimer) { 346 if (_connectTimer) {
355 [self.connectTimer invalidate]; 347 [self.connectTimer invalidate];
356 self.connectTimer = nil; 348 self.connectTimer = nil;
357 } 349 }
  350 + [NSObject cancelPreviousPerformRequestsWithTarget:self];
358 _needSendStartPackage = YES; 351 _needSendStartPackage = YES;
359 [_socket disconnect]; 352 [_socket disconnect];
360 } 353 }