- (void)chatDidReceiveMessage:(QBChatMessage *) 消息不工作
- (void)chatDidReceiveMessage:(QBChatMessage *)message not working
我已经集成了 QuickBlox iOS sdk v2.5。我正在向特定对象发送消息,它们被发送到服务器但用于接收消息
- (void)chatDidReceiveMessage:(QBChatMessage *)消息未被调用
这就是我正在做的连接
[[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];
用于创建聊天对话框
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
}];
然后发送消息
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);
}];
消息已发送到聊天室,但其他用户无法接收。- (void)chatDidReceiveMessage:(QBChatMessage *) 消息未被调用。或者可能是我使用了错误的功能。
您不是在发送消息,而是在 REST 中创建它。所以 QBChat 委托 'chatDidReceiveMessage' 不会被调用。它仍然是有效的事情,但是要接收这样的消息,您需要从 REST 下载它(例如 '[QBRequest messagesForDialogID:completionBlock:errorBlock:]' )。
为了通过委托接收消息,您需要使用 QBChatDialog 的 'sendMessage:completion:',它使用 XMPP 发送和接收消息。
在您的情况下,您应该这样做:
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);
}
}];
我已经集成了 QuickBlox iOS sdk v2.5。我正在向特定对象发送消息,它们被发送到服务器但用于接收消息 - (void)chatDidReceiveMessage:(QBChatMessage *)消息未被调用
这就是我正在做的连接
[[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];
用于创建聊天对话框
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
}];
然后发送消息
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);
}];
消息已发送到聊天室,但其他用户无法接收。- (void)chatDidReceiveMessage:(QBChatMessage *) 消息未被调用。或者可能是我使用了错误的功能。
您不是在发送消息,而是在 REST 中创建它。所以 QBChat 委托 'chatDidReceiveMessage' 不会被调用。它仍然是有效的事情,但是要接收这样的消息,您需要从 REST 下载它(例如 '[QBRequest messagesForDialogID:completionBlock:errorBlock:]' )。
为了通过委托接收消息,您需要使用 QBChatDialog 的 'sendMessage:completion:',它使用 XMPP 发送和接收消息。 在您的情况下,您应该这样做:
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);
}
}];