• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - Quickblox 聊天室确实收到消息未通话

[复制链接]
菜鸟教程小白 发表于 2022-12-13 11:20:28 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我遇到了一个问题,我在群组类型 QBChatDialogTypePublicGroup 中聊天时没有收到消息。但是,我可以在日志中看到消息正在发送给我。根据quickblox官方网站的解释,收到消息时应调用以下方法

- (void)chatRoomDidReceiveMessageQBChatMessage )message fromDialogIdNSString )dialogId
- (void)chatDidNotSendMessageQBChatMessage )message toDialogIdNSString )dialogId errorNSError *)error

但以上委托(delegate)都没有调用。

这是我采取的步骤 -


登录:-


[QBRequest logInWithUserLogin:[[AppDelegate sharedAppDelegate]getQBUserInstance].login password:[[AppDelegate sharedAppDelegate]getQBUserInstance].password successBlock:^(QBResponse response, QBUUser user) {

    NSLog(@"quickblox user id is %lu", (unsigned long)user.ID);
    [[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat"%lu", (unsigned long)user.ID]forKey"QuickbloxUserID"];

    [[AppDelegate sharedAppDelegate]getQBUserInstance].ID=user.ID; 

    // set Chat delegate
    [[QBChat instance] addDelegate:self];

    // login to Chat
    [[QBChat instance] loginWithUser:[[AppDelegate sharedAppDelegate]getQBUserInstance]];


} errorBlock:^(QBResponse *response) {

    // error handling
    NSLog(@"error: %@", response.error);
}];


-(void) chatDidLogin{

    [QBChat instance].keepAliveInterval = 30;
    [QBChat instance].autoReconnectEnabled = YES;
    [QBChat instance].streamManagementEnabled = YES;

    NSLog(@"You have successfully signed in to QuickBlox Chat");

    [MyNetWorking endHud];
    FMTabBarController *vc = [self.storyboard instantiateViewControllerWithIdentifier"tabView"];
    [AppDelegate sharedAppDelegate].window.rootViewController=vc;

    //[self presentViewController:vc animated:YES completion:nil];
}


- (void)chatDidNotLoginWithErrorNSError *)error{
    NSLog(@"You have successfully signed in to QuickBlox Chat %@", error.domain);
    NSLog(@"You have successfully signed in to QuickBlox Chat %@", error.userInfo);
    NSLog(@"You have successfully signed in to QuickBlox Chat %@", error.localizedDescription);
}


- (void)chatDidConnect{
    NSLog(@"You have successfully signed in to QuickBlox Chat");
}


- (void)chatDidAccidentallyDisconnect{
    NSLog(@"You have successfully signed in to QuickBlox Chat");
}


- (void)chatDidReconnect{
    NSLog(@"You have successfully signed in to QuickBlox Chat");
}

要加入群组,我使用了以下代码


groupChatDialog = [[QBChatDialog alloc] initWithDialogID:self.groupChatID typeBChatDialogTypePublicGroup];
NSLog(@"Chat dialog %@", [QBChat instance].delegates);

// [[QBChat instance] addDelegate:self];
// NSLog(@"Chat dialog %@", [QBChat instance].delegates);

[groupChatDialog setOnJoin:^() {
    [[[UIAlertView alloc] initWithTitle"FM" message"Group Joined Successfully" delegate:nil cancelButtonTitle"Ok" otherButtonTitles"Cancel", nil] show];
}];

[groupChatDialog setOnJoinFailed:^(NSError *error) {
    [[[UIAlertView alloc] initWithTitle"FM" message:error.localizedDescription delegate:nil cancelButtonTitle"Ok" otherButtonTitles"Cancel", nil] show];
    NSLog(@"Error is %@", error);

}];
[groupChatDialog join];

************************************************************
To fetch previous chat I have used the following code
************************************************************

QBResponsePage *resPage = [QBResponsePage responsePageWithLimit:20 skip:0];

[QBRequest messagesWithDialogID:self.groupChatID extendedRequest:nil forPage:resPage successBlock:^(QBResponse response, NSArray messages, QBResponsePage *responcePage) {

    NSLog(@"messages are %@", messages);
    [arrayChat addObjectsFromArray:messages];
    [self.tableView reloadData];

} errorBlock:^(QBResponse *response) {
    NSLog(@"error: %@", response.error);
}];

为了发送消息,我使用了以下代码


messageToSent = [QBChatMessage message];

[messageToSent setText:_textField.text];
[messageToSent setDateSent:[NSDate date]];

NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES;
[messageToSent setCustomParameters:params];
[groupChatDialog sendMessage:messageToSent];

_textField.text = @"";
[arrayChat addObject:messageToSent];
[_tableView reloadData];

在此之后,我希望调用以下方法


- (void)chatRoomDidReceiveMessageQBChatMessage )message fromDialogIdNSString )dialogId{
    NSLog(@"message is %@", message);
}

- (void)chatDidNotSendMessageQBChatMessage )message toDialogIdNSString )dialogId error:(NSError *)error{
    [[[UIAlertView alloc] initWithTitle:@"FM" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil] show];
    NSLog(@"Error is %@", error);
}

但是他们没有被调用,但是他们应该按照网站上的解释被调用。请让我知道我在这里缺少什么或我做错了什么。



Best Answer-推荐答案


首先确保你已经设置了 QBChat 代理,在下面设置使用代码

QBChat.instance.addDelegate(self)

如果您的委托(delegate)方法没有调用,请确保您已连接到聊天。如果您未连接到聊天,将不会调用代表。

尝试使用以下代码连接聊天,然后重试。

*Swift 代码

QBChat.instance.connect(withUserID: "user_id",
                            password: "password",
                            completion: { [weak self] error in
        guard let self = self else { return }
        if let error = error
            print("Error occured while connecting to chat")
        } else {
            print("successfully connected to chat.")
            self.onCompleteAuth?()
        }
    })

Note: chat connection can be lost for some reasons, 1. lost connection to internet, 2. App went in background or got suspended. 3. if you're presenting controllers like UIImagePickerController, Camera, UIDocumentPickerController etc.

Read more about connection lost in quickblox

关于ios - Quickblox 聊天室确实收到消息未通话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33139412/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap