使用 quickblox 发送消息

send message using quickblox

我已经在我的应用程序中集成了 quickblox。因为我使用此代码

在 table 视图中获取了所有用户
 QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:100];
         [QBRequest usersForPage:page successBlock:^(QBResponse *response, QBGeneralResponsePage *pageInformation, NSArray *users)
          {

                  [_NameArray addObjectsFromArray:users];

          }
                      errorBlock:^(QBResponse *response)
          {

          }];
    }
        errorBlock:^(QBResponse *response)
     {

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

在 _nameArray 中我有 QBUUSER 对象形式的所有用户信息

QBUUser *obj = [Array objectAtIndex:indexPath.row];
NSString *name = obj.fullname;

正在检索所有用户。现在,当 loginUser 单击特定联系人或检索用户时,我会使用此代码

创建私人群组一对一通信
-(void)chat
{
    chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];

    chatDialog.occupantIDs = @[@(chatuserobj.ID)];

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

    } errorBlock:^(QBResponse *response) {

    }];



}

主要是在那个视图控制器中发送和接收消息我已经使用了文本字段来发送消息和table视图来显示消息来发送消息我已经使用了这个代码

    -(void)startChat
{
    [[QBChat instance] addDelegate:self];


    QBChatMessage *message = [QBChatMessage message];

    [message setText:@"Hey there"];


    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"save_to_history"] = @YES;
    [message setCustomParameters:params];


    [chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
    {
        NSLog(@"Message sent");

    }];

}

并在委托方法下方使用

- (void)chatDidReceiveMessage:(QBChatMessage *)message

我确实在 quickblox 的管理面板中看到了私人群组,但看不到已发送的消息。请帮助我。

而不是你的代码:

[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
    NSLog(@"Message sent");

}];

使用以下代码:

   [QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
  NSLog(@"success: %@", createdMessage);
} errorBlock:^(QBResponse *response) {
  NSLog(@"ERROR: %@", response.error);
}];

我使用如下代码:

  #pragma mark Tool bar Actions
    - (void)didPressSendButton:(UIButton *)button
       withMessageText:(NSString *)text
              senderId:(NSUInteger)senderId
     senderDisplayName:(NSString *)senderDisplayName
                  date:(NSDate *)date {
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:text];
message.senderID = senderId;
message.recipientID= [[NSUserDefaults standardUserDefaults] integerForKey:@"CurrentRecipientID"];
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);
[self.chatSectionManager addMessage:createdMessage];
} errorBlock:^(QBResponse *response) {
 NSLog(@"ERROR: %@", response.error);
}];

[self finishSendingMessageAnimated:YES];

}