3

I use the sample code in github for ios sdk and I added my account details but when I send a message in chatviewcontroller I got this log:

-[QBChat sendMessage:] -> return. You have to be logged in in order to use Chat API I tried many solutions with no success this my code I create a session :

-(void)goToProfile{

    QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
    extendedAuthRequest.userLogin =email.text;
    extendedAuthRequest.userPassword =motDePasse.text;

    [QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self ];

}

after that in the completedWithResult:(Result *)result context:(void *)contextInfo :

// QuickBlox API queries delegate
-(void)completedWithResult:(Result *)result  context:(void *)contextInfo{
    NSLog(@"errors=%@", result.errors);
    // QuickBlox User authentication result
    if([result isKindOfClass:[QBUUserLogInResult class]]){

        // Success result
        if(result.success){

            QBUUserLogInResult *res = (QBUUserLogInResult *)result;
            NSLog(@"------------Logged In user=%@", res);
            // Read about Chat password there http://quickblox.com/developers/Chat#Password
            //
            if([((__bridge NSString *)contextInfo) isEqualToString:socialLoginContext]){
                res.user.password = [QBBaseModule sharedModule].token;
            }else{
                res.user.password = motDePasse.text;
            }
            // Save current user
            //
            [[LocalStorageService shared] setCurrentUser: res.user];


            // Login to QuickBlox Chat
            //
            [[ChatService instance] loginWithUser:[LocalStorageService shared].currentUser completionBlock:^{
                 NSLog(@"------------local sotrage Logged In user=%@", [LocalStorageService shared].currentUser);
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You have successfully logged in"
                                                                message:nil
                                                               delegate:nil
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles: nil];
                [alert show];
                //
                // hide alert after delay
                double delayInSeconds = 2.0;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                    [alert dismissWithClickedButtonIndex:0 animated:YES];
                });


            }];

            [[UserChoice sharedUserChoice]setIsConnectedUser:1];
            MySlideViewController *slideViewController = [[MySlideViewController alloc] initWithNibName:@"SlideViewController" bundle:nil];
            slideViewController.myDataUser = resultG;
            slideViewController.delegate = slideViewController;
            [[UserChoice sharedUserChoice] setMyUserProfile:resultG];
            slideViewController.myDataUserIn = [[UserChoice sharedUserChoice]myUserProfile];
            slideViewController.paramGeolocalisation = paramGeo;
            [self.navigationController pushViewController:slideViewController animated:YES];
            self.navigationController.navigationBarHidden = YES;
            // Errors
        }else{
            NSString *errorMessage = [[result.errors description] stringByReplacingOccurrencesOfString:@"(" withString:@""];
            errorMessage = [errorMessage stringByReplacingOccurrencesOfString:@")" withString:@""];

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errors"
                                                            message:errorMessage
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles: nil];
            [alert show];

        }
    }

}
Rubycon
  • 18,156
  • 10
  • 49
  • 70
Dhekra Zaied
  • 97
  • 10

2 Answers2

1

It means that you're trying to send a message, but still don't logged in.

Check this guide

http://quickblox.com/developers/SimpleSample-chat_users-ios

// login to Chat
[[QBChat instance] loginWithUser:currentUser];

#pragma mark -
#pragma mark QBChatDelegate

// Chat delegate
-(void) chatDidLogin{
    // You have successfully signed in to QuickBlox Chat

    // Now you can send a message

}
Rubycon
  • 18,156
  • 10
  • 49
  • 70
0

Looks like you should update your code this way:

// Login to QuickBlox Chat
[[ChatService instance] loginWithUser:[LocalStorageService shared].currentUser completionBlock:^{
    NSLog(@"------------local sotrage Logged In user=%@", [LocalStorageService shared].currentUser);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You have successfully logged in"
                                                                message:nil
                                                               delegate:nil
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles: nil];
    [alert show];
    //
    // hide alert after delay
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    });



    [[UserChoice sharedUserChoice]setIsConnectedUser:1];
    MySlideViewController *slideViewController = [[MySlideViewController alloc] initWithNibName:@"SlideViewController" bundle:nil];
    slideViewController.myDataUser = resultG;
    slideViewController.delegate = slideViewController;
    [[UserChoice sharedUserChoice] setMyUserProfile:resultG];
    slideViewController.myDataUserIn = [[UserChoice sharedUserChoice]myUserProfile];
    slideViewController.paramGeolocalisation = paramGeo;
    [self.navigationController pushViewController:slideViewController animated:YES];
    self.navigationController.navigationBarHidden = YES;

}];
Rubycon
  • 18,156
  • 10
  • 49
  • 70
  • like this it didn't enter in th block that's why I pu it outside – Dhekra Zaied Jun 06 '14 at 10:19
  • I moved code which pushes nav controller into login callback block – Rubycon Jun 06 '14 at 10:22
  • like this it didn't enter in th block that's why I put it outside an d I don't know why and get the logs :-[QBChat loginWithUser:] -> Connecting to Chat, hostName: muc.chat.quickblox.com -[QBChat loginWithUser:] -> Chat server endpoint: muc.chat.quickblox.com, User JID: 1181331-10772@chat.quickblox.com – Dhekra Zaied Jun 06 '14 at 10:23
  • Also I get code 0 in the methode chatDidFailWithError, it's not an error from app in admin panel? – Dhekra Zaied Jun 06 '14 at 10:26
  • Please print your user res.user – Rubycon Jun 06 '14 at 11:41
  • ------------Logged In user= [QBUUser]: ID:1188563 created at:2014-06-06 08:36:29 +0000 updated at:2014-06-06 08:36:29 +0000 externalUserID:0 blobID:0 facebookID:(null) twitterID:(null) full name:(null) email:(null) login:nomgmail.com phone:(null) tags:(null) lastRequestAt:2014-06-06 12:26:05 +0000 website:(null) – Dhekra Zaied Jun 06 '14 at 12:27
  • note that I get my list of users but when i want to chat with another user I get :-[QBChat sendMessage:] -> return. You have to be logged in in order to use Chat API – Dhekra Zaied Jun 06 '14 at 12:28
  • 1
    the problem was a firewall port happy it's working now like a sharm – Dhekra Zaied Jun 09 '14 at 08:41