简体   繁体   中英

send message using quickblox

I've integrated quickblox in my app. as I fetched all user in tableview using this code

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

in _nameArray I've all user information in QBUUSER object form

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

in retrieve all user. now when loginUser click on particular contact or retrieve user then i create private group one to one communication using this code

-(void)chat
{
    chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];

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

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

    } errorBlock:^(QBResponse *response) {

    }];



}

and main thing send and receive message in that view controller i have taken textfield for sending message and table view for show message for sending message i have used this code

    -(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");

    }];

}

and used below delegate method

- (void)chatDidReceiveMessage:(QBChatMessage *)message

I actually see the private group in admin panel of quickblox but don't see the sent message. please help me.

Instead of you're code like:

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

}];

Use the following code:

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

I use Code like:

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM