【问题标题】:Quickblox unable to send message chatQuickblox 无法发送消息聊天
【发布时间】:2014-07-26 04:19:26
【问题描述】:

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

        }
    }

}

【问题讨论】:

    标签: ios xmpp chat message quickblox


    【解决方案1】:

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

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

    【讨论】:

    • 像这样它没有进入区块所以我把它放在外面
    • 我移动了将导航控制器推送到登录回调块中的代码
    • 像这样它没有进入区块,这就是为什么我把它放在外面并且我不知道为什么并获取日志:-[QBChat loginWithUser:] -> 连接到聊天,主机名:muc.chat.quickblox.com -[QBChat loginWithUser:] -> 聊天服务器端点:muc.chat.quickblox.com,用户 JID:1181331-10772@chat.quickblox.com
    • 另外我在方法chatDidFailWithError中得到代码0,这不是管理面板中的应用程序错误吗?
    • 问题是防火墙端口很高兴它现在像沙姆一样工作
    【解决方案2】:

    表示您正在尝试发送消息,但仍未登录。

    查看本指南

    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
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 2022-01-21
      • 2016-06-29
      • 1970-01-01
      相关资源
      最近更新 更多