Quickblox聊天室收到的消息没有调用

时间:2015-10-15 03:33:50

标签: ios iphone quickblox

我正面临一个问题,当我在群组类型QBChatDialogTypePublicGroup聊天时,我没有收到消息。但是,我可以在日志中看到消息即将发送给我。根据quickblox官方网站的说明,在收到消息时应该调用以下方法

- (void)chatRoomDidReceiveMessage:(QBChatMessage )message fromDialogId:(NSString )dialogId
- (void)chatDidNotSendMessage:(QBChatMessage )message toDialogId:(NSString )dialogId error:(NSError *)error

但上述代表都没有打电话。

这是我采取的步骤 -

登录: -

[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)chatDidNotLoginWithError:(NSError *)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 type:QBChatDialogTypePublicGroup];
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)chatRoomDidReceiveMessage:(QBChatMessage )message fromDialogId:(NSString )dialogId{
    NSLog(@"message is %@", message);
}

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

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

1 个答案:

答案 0 :(得分:1)

正确的方法是

-(void) chatRoomDidReceiveMessage:(QBChatMessage *)message fromDialogID:(NSString *)dialogID

不是fromDialogId