I am using QuickBlox-iOS SDK
for chatting. Login/Signup is working perfectly. Also I am able to send message but the delegate method
- (void)chatDidReceiveMessage:(QBChatMessage *)message;
is not getting called. Here's the code I am using to setup chat. Adding the following code in appDelegate :
// connect to Chat
[[QBChat instance] addDelegate:self];
QBUUser *currentUser = [QBUUser user];
currentUser.ID = [Global sharedInstance].currentUser.ID;
currentUser.password = @"password";
[[QBChat instance] connectWithUser:currentUser completion:^(NSError * _Nullable error) {
NSLog(@"connect to chat error %@",error);
}];
And the below code I am using to send message :
QBChatMessage *message = [QBChatMessage message];
message.recipientID=[Global sharedInstance].QBUserID;
message.senderID=[Global sharedInstance].currentUser.ID;
[message setText:messageTextView.text];
message.dateSent = [NSDate date];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES;
[message setCustomParameters:params];
[QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
NSLog(@"success: %@", createdMessage);
} errorBlock:^(QBResponse *response) {
NSLog(@"ERROR: %@", response.error);
}]
I checked on QuickBlox
dashboard. It shows all the sent/received messages. But the delegate is not getting called when I send message to another user. I am not using any additional services classes (QMServices
) like they are using in their Example Project. Any help would be appreciated. Thanks
I don't understand why you're using the
[QBRequest createMessage:successBlock:errorBlock:]
method to send messages to another user.For me what always worked was to create a chatDialog with the user you're trying to message, like so:
Afterwards, you can call Quickblox method to create the dialog on the servers:
Create the message:
And then send the message to the dialog:
I think following this flux you'll be able to receive the callback through the delegate.
EDIT - I forgot to mention the consts I used in the code above are:
Have you added
<QBChatDelegate>
into your .h file.