Commit 53be8feb04deaeaf87c3285d23466d0e6e4707c2

Authored by 王军波
1 parent bbb09e39

302

CNLiveChatSDKDemo/CNLiveChatSDKDemo/AppDelegate.m
... ... @@ -39,7 +39,7 @@
39 39 // 除非您已经手动将连接断开,或者杀死程序,或者少数无法自动重连的情况,否则您不需要自己再手动重连。
40 40 // 客户端使用时可以判断一下当前用户的登录状态,未登录就用上面的 connectServer 的方法连接服务器,已登录就用 loginServer 此方法连接服务器;
41 41  
42   - CNLiveChatUserInfo *userInfo = [[CNLiveChatUserInfo alloc] initWithUserId:@"20170717" name:@"11" portrait:@""];
  42 + CNLiveChatUserInfo *userInfo = [[CNLiveChatUserInfo alloc] initWithUserId:@"20170719528" name:@"11" portrait:@""];
43 43  
44 44 [[CNLiveChatManager sharedCNLiveChatManager] loginServer:userInfo success:^(NSString *userId) {
45 45  
... ...
CNLiveChatSDKDemo/CNLiveChatSDKDemo/ChatRoomViewController.m
... ... @@ -73,6 +73,34 @@ static NSString *imageCellId = @"imageCellId";
73 73  
74 74 } error:^(CNLiveChatErrorCode errors, NSString *targetId) {
75 75 NSLog(@"加入聊天室:%@失败,错误码:%ld",targetId,(long)errors);
  76 +
  77 + if (errors == CNLive_ERRORCODE_BY_TOKENERROR) { //发送消息或加入聊天室遇此错误(302)是因为连接失败,需重新做连接
  78 +
  79 + CNLiveChatUserInfo *userInfo = [[CNLiveChatUserInfo alloc] initWithUserId:@"20170719528" name:@"11" portrait:@""];
  80 +
  81 + [[CNLiveChatManager sharedCNLiveChatManager] loginServer:userInfo success:^(NSString *userId) {
  82 +
  83 + [[CNLiveChatManager sharedCNLiveChatManager] joinChatRoom:chatRoomId messageCount:10 success:^(NSString *targetId) {
  84 +
  85 + NSLog(@"已成功加入聊天室:%@",targetId);
  86 +
  87 + [self getChatRoomPersonCount]; // 获取聊天室人数
  88 + dispatch_async(dispatch_get_global_queue(0, 0), ^{
  89 + _getCountTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getChatRoomPersonCount) userInfo:nil repeats:YES];
  90 + [[NSRunLoop currentRunLoop] run];
  91 + });
  92 +
  93 + } error:^(CNLiveChatErrorCode errors, NSString *targetId){
  94 +
  95 + NSLog(@"");
  96 + }];
  97 +
  98 + } error:^(CNLiveChatConnectErrorCode errors) {
  99 +
  100 + NSLog(@"");
  101 + }];
  102 + }
  103 +
76 104 }];
77 105  
78 106 [self.view addSubview:self.tableView];
... ... @@ -85,6 +113,7 @@ static NSString *imageCellId = @"imageCellId";
85 113 _messageArrayM = [[NSMutableArray alloc] init];
86 114 }
87 115  
  116 +
88 117 - (void)createBackButton {
89 118 self.navigationItem.hidesBackButton = YES;
90 119 UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
... ... @@ -277,7 +306,7 @@ static NSString *imageCellId = @"imageCellId";
277 306  
278 307 - (void)onConnectionStatusChanged:(CNLiveConnectionStatus)status {
279 308  
280   - NSLog(@"当前连接状态:%ld",(long)status);
  309 + NSLog(@">>>>>>> 当前连接状态:%ld",(long)status);
281 310 }
282 311  
283 312 - (void)onChatRoomJoined:(NSString *)chatroomId {
... ... @@ -705,6 +734,8 @@ static NSString *imageCellId = @"imageCellId";
705 734 [self.textField resignFirstResponder];
706 735 }
707 736  
  737 +
  738 +
708 739 - (void)didReceiveMemoryWarning {
709 740 [super didReceiveMemoryWarning];
710 741 // Dispose of any resources that can be recreated.
... ...