Search code examples
iosquickblox

Working with Chat feature in Quickblox in iOS


I want to implement chat feature in my app,its actually one to one chat,i have downloaded sample code from quickblox.com

I have registered in Quickblox and just added my credentials in sample application which I downloaded, I'm getting the following issues

1.404 and Token is required.

I'm unsure whether I need to use API calls and where I can find API calls.

Can anybody please explain or provide me sample code to work.


Solution

  • I just implemented chat feature in my app. So I am elaborate you short description of how to enable chat in your app using Quickblox.Integrate sdk of Quickblox in your app or use pod.

    First of all go through this link quickblox ios chat tutorial than create users register users from here than in your app, login in Quickblox by using this code

    Method to login in Quickblox

    [QBRequest logInWithUserLogin: self.Name.text password:self.Password.text  successBlock:^(QBResponse *response, QBUUser *user)
     {
    
     }
                       errorBlock:^(QBResponse *response)
     {
    
         NSLog(@"error: %@", response.error);
     }];
    

    Dialog box means to create session between users like : one to one or group chat

    You need to create dialog box in order to enable chat, here is demo code of how to create dialog

    //create dialog
    
    QBChatDialog *chatDialog = [[QBChatDialog alloc] initWithDialogID:null type:QBChatDialogTypeGroup];
    chatDialog.name = @"Chat with Bob, Sam, Garry";
    chatDialog.occupantIDs = @[@(55), @(678), @(22)];
    
    // change id with your register user's id
    
    [QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog)
     {
    
     } errorBlock:^(QBResponse *response)
     {
    
     }];
    
    // you can see created dialogbox in your quickblox admin panel in chat option
    **//retrive list of buddies**
    
    QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:10];
    [QBRequest usersForPage:page successBlock:^(QBResponse *response, QBGeneralResponsePage *pageInformation, NSArray *users)
     {
         NSLog(@"%lu",(unsigned long)users.count);
         for (int i=0; i<users.count; i++)
         {
             QBUUser *user = [users objectAtIndex:i];
             [buddyData addObject:user];
         }
         [self.buddyList reloadData];
     }
                 errorBlock:^(QBResponse *response)
     {
     } ];
    

    This is basic setup of Quickblox in your app. All details are already given in Quickblox tutorial. If you need any help than just tell me.