我将github中的示例代码用于ios sdk,并添加了我的帐户详细信息,但是当我在chatviewcontroller中发送消息时,得到了以下日志:

-[QBChat sendMessage:]->返回。您必须先登录才能使用Chat API
我尝试了许多解决方案,但均未成功,因此我创建了一个会话:

-(void)goToProfile{

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

    [QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self ];

}

之后在completedWithResult:(Result *)结果上下文:(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];

        }
    }

}

最佳答案

看起来您应该以这种方式更新代码:

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

}];

关于ios - Quickblox无法发送消息聊天,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24055678/

10-10 16:05