3

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.

Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
Mad Burea
  • 531
  • 8
  • 22
  • Did you get an error on the message sending or on the dialog creation? If yes, please update this question. – VitGur Aug 01 '16 at 10:33

1 Answers1

4

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

}
Mannam Brahmam
  • 2,225
  • 2
  • 24
  • 36