使用quickblox发送消息

时间:2016-07-11 07:47:46

标签: ios objective-c quickblox

我已在我的应用中集成了quickblox。当我使用此代码

获取tableview中的所有用户时
 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) {

    }];



}

主要事情发送和接收消息在该视图控制器中我已经采取文本字段发送消息和表视图显示消息发送消息我使用此代码

    -(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的管理面板中看到了私人组,但是没有看到发送的消息。请帮帮我。

1 个答案:

答案 0 :(得分:4)

而非您的代码如下:

[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);
}];

我使用Code代码:

  #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];

}