简体   繁体   English

QuickBlox聊天未登录

[英]QuickBlox Chat not logging in

I'm working on swift and quickblox and I'm trying to have chatting occur between users. 我正在研究swift和quickblox,并且试图在用户之间进行聊天。 The user authentication and sign in is working its just that the chat isn't Logging in for some reason Code in question: 用户身份验证和登录正在工作,只是由于某种原因聊天未登录。有问题的代码:

                QBRequest.createSessionWithExtendedParameters(parameters, successBlock: { (response : QBResponse! ,session : QBASession!) -> Void in

                var currentUser = QBUUser()
                currentUser.ID = session.userID
                currentUser.password = userPassword as String
                QBChat().addDelegate(self)
                QBChat().loginWithUser(currentUser)



                let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
                appDelegate.initiateLocationServicesUpdates()

                self.boxView.removeFromSuperview()

                self.performSegueWithIdentifier("alreadySignedInSegue", sender: self)


                }, errorBlock: { (response : QBResponse!) -> Void in
                    self.boxView.removeFromSuperview()
                    NSLog("error: %@", response.error);
                    self.view.userInteractionEnabled = true
                    var alert : UIAlertController = UIAlertController()
                    let action : UIAlertAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
                    if let error = response.error.reasons{
                        if  response.error.reasons.description.rangeOfString("Unauthorized") != nil{
                            alert = UIAlertController(title: "Oops", message: "Wrong Username/Password Combination", preferredStyle: UIAlertControllerStyle.Alert)
                            alert.addAction(action)
                            self.presentViewController(alert, animated: true, completion: nil)
                        }
                    }
                    else{
                        alert = UIAlertController(title: "Oops", message: "Something Went Wrong, Its Our Fault!", preferredStyle: UIAlertControllerStyle.Alert)
                        alert.addAction(action)
                        self.presentViewController(alert, animated: true, completion: nil)
                    }
            })

the segue found in the success block works but the value of QBChat().isLoggedIn() is always false and if I try to send a message to a user id via the 成功块中找到的segue起作用,但是QBChat()。isLoggedIn()的值始终为false,如果我尝试通过以下方式向用户ID发送消息

QBChat().sendMessage(message: QBChatMessage!)

function I end up getting a "Must me logged in to chat to be able to send" message . 功能我最终收到“必须登录才能聊天”消息。 It must be a small problem that's due to me overlooking something. 这一定是一个小问题,原因是我忽略了某些东西。

edit: just so you know this is my first time working with quickblox, so please be precise about what I'm doing wrong edit:就是这样,您才知道这是我第一次使用quickblox,因此请准确说明我做错了什么

You should use a shared instance of QBChat for working with chat. 您应该使用QBChat的共享实例进行聊天。

QBChat.instance().addDelegate(self)
QBChat.instance().loginWithUser(currentUser)

Also check 还要检查

setAutoCreateSessionEnabled

method in QBConnection. QBConnection中的方法。 You can forget about session management. 您可以忘记会话管理。

Please check my code working on Objective-C language. 请检查我在Objective-C语言上工作的代码。

For more info kindly check 欲了解更多信息,请检查

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

}];

or Do this 或这样做

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM