Quickblox无法发送聊天消息。

3

我使用GitHub中的示例代码来使用iOS SDK,并添加了我的帐户详细信息,但是当我在ChatViewController中发送消息时,我得到了这个日志:

-[QBChat sendMessage:] -> 返回。您必须登录才能使用聊天API

我尝试了许多解决方案,但都没有成功。这是我创建会话的代码:

-(void)goToProfile{

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

    [QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self ];

}

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

        }
    }

}
2个回答

1
这意味着您正在尝试发送消息,但仍未登录。
请查看此指南。

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

}

0

看起来你应该这样更新你的代码:

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

}];

就像这样,它没有进入块中,所以我把它放在外面。 - Dhekra Zaied
我将推送导航控制器的代码移动到登录回调块中。 - Rubycon
我在chatDidFailWithError方法中得到了代码0,这不是来自管理员面板的错误吗? - Dhekra Zaied
请打印您的用户 res.user。 - Rubycon
1
问题是防火墙端口,现在很高兴它可以正常工作。 - Dhekra Zaied
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接