Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

- (void)chatDidReceiveMessage:(QBChatMessage *)message not working

I have integerated QuickBlox iOS sdk v2.5. I am sending messages to a particular and they are being sent to server but for receiving a message - (void)chatDidReceiveMessage:(QBChatMessage *)message is not getting called

This is what I am doing to connect

[[QBChat instance] addDelegate:self];

QBUser *chatUser=[QBUser new];
chatUser.ID=[[[NSUserDefaults standardUserDefaults] objectForKey:USERID] integerValue];
chatUser.password=[[NSUserDefaults standardUserDefaults] objectForKey:PASSWORD];
[[QBChat instance] connectWithUser:chatUser completion:nil];

For creating a chatDialog

QBChatDialog *chatDialog=[[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];

chatDialog.name = @"Chat with Garry";

NSMutableArray *chatPartners=[[NSMutableArray alloc] initWithObjects:[chatPartner objectForKey:@"id"] ,[[NSUserDefaults standardUserDefaults] objectForKey:USERID], nil];

chatDialog.occupantIDs=chatPartners;

[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) {
    //Success

    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:response.data options:kNilOptions error:nil];

    [[NSUserDefaults standardUserDefaults] setObject:[json object
} errorBlock:^(QBResponse *response) {

 //error

}];

Then to send message

QBChatMessage *message =[QBChatMessage message];
[message setText:self.messageText.text];

params[@"messageStatus"]=@"Test Message";
params[@"save_to_history"] = @YES;

[message setCustomParameters:params];

[message setRecipientID:[[[NSUserDefaults standardUserDefaults] objectForKey:PARTNERID] integerValue]]; //



[QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {

    self.messageText.text = @"Type Here...";
    [self addMessagetoChat:createdMessage];


    NSLog(@"success: %@", createdMessage);
} errorBlock:^(QBResponse *response) {
    self.messageText.text = @"Type Here...";
    NSLog(@"ERROR: %@", response.error);
}];

Message is sent to the chat but the other user is not able to receive it.- (void)chatDidReceiveMessage:(QBChatMessage *)message is not getting called. Or may b I am using the wrong function.

like image 739
Muhammad Nayab Avatar asked Jun 05 '26 01:06

Muhammad Nayab


1 Answers

You are not sending message, but creating it in the REST. So QBChat delegate 'chatDidReceiveMessage' will not be called. It is still valid thing to do, however to receive such message you need to download it from REST (e.g. '[QBRequest messagesForDialogID:completionBlock:errorBlock:]' ).

In order to receive messages through delegate you need to use 'sendMessage:completion:' of QBChatDialog, which is using XMPP to send and receive messages. In your situation you should do this:

QBChatMessage *message =[QBChatMessage message];
[message setText:self.messageText.text];

params[@"messageStatus"]=@"Test Message";
params[@"save_to_history"] = @YES;

[message setCustomParameters:params];

[message setRecipientID:[[[NSUserDefaults standardUserDefaults] objectForKey:PARTNERID] integerValue]];

[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error) {
    if (error != nil) {
        NSLog(@"Failed to send message with error: %@", error);
    }
}];
like image 186
Raikerian Avatar answered Jun 08 '26 00:06

Raikerian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!