聊天失败后自动离开聊天室。为什么?哦,为什么?[Quickblox]
每次我们尝试在chatDidFail事件后重新连接时,我们:聊天失败后自动离开聊天室。为什么?哦,为什么?[Quickblox],quickblox,Quickblox,每次我们尝试在chatDidFail事件后重新连接时,我们: 登录聊天室 进屋 自动被踢出房间(聊天室DidLeave事件) 当我们试图重新加入房间时,我们又被踢了出去(聊天室DidLeave) 它会循环 为什么,为什么? 在我们尝试重新连接chatDidFail事件后,为什么Quickblox会将我们踢出任何房间 我们所做的就是: -(void)chatDidFailWithError:(int)code { [[QBChat instance] loginWithUser:curre
-(void)chatDidFailWithError:(int)code
{
[[QBChat instance] loginWithUser:currentUser];
}
- (void)chatRoomDidLeave:(NSString *)roomName
{
[[QBChat instance] createOrJoinRoomWithName:@"roomName" membersOnly:NO persistent:YES];
}
关于这个问题,我们的想法已经没有了……我设法解决了这个问题。当应用程序进入后台并且您没有离开聊天室时,Quickblox聊天实现似乎无法自行恢复 这可以通过让ChatManager(您自己的用于管理聊天连接的单例类)存储当前显示的聊天室(self.currentRoom)并自动离开聊天室来解决,并在应用程序退出活动时注销。当应用程序进入前台时,您登录并重新加入房间 将这些添加到singleton类
(id)init
:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationWillResignActiveNotification:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationEnterForegroundNotification:) name:UIApplicationWillEnterForegroundNotification object:nil];
以及当前房间的属性实现:
@property (nonatomic, strong) QBChatRoom *currentRoom;
然后实现相应的处理程序(您也可以在此处使状态计时器无效):
然后在chatDidLogin
中执行以下操作:
- (void)chatDidLogin
{
...
if (self.currentRoom) {
lg(@"Auto-joining current room.");
[self joinRoom:self.currentRoom completionBlock:nil];
}
...
}
输入房间时存储房间参照:
- (void)chatRoomDidEnter:(QBChatRoom *)room
{
...
self.currentRoom = room;
...
}
当您在
UIApplicationWillResignActiveNotification
上离开会议室时,请确保您没有清除self.currentRoom
,以便在应用程序出现在前台时,有一个当前会议室的参考。是您的代码还是?是:您是否实现了委托方法chatRoomDidNotEnter:错误:?这个方法会被激活吗?如果是的话,它包含了哪一个错误?chatRoomDidNotEnter被实现了,并且没有被激活。嗯,我没有任何想法。也许你的代码中有错误的逻辑。或者别的什么。您在chatDidLogin方法中拥有什么?您是否也在其中调用-createOrJoinRoomWithName:?
- (void)chatRoomDidEnter:(QBChatRoom *)room
{
...
self.currentRoom = room;
...
}