Question

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

        }
    }

}
Was it helpful?

Solution

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;

}];

OTHER TIPS

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top