ios - QuickBlox Chat 未登录

标签 ios swift authentication chat quickblox

我正在开发 swift 和 quickblox,我正在尝试让用户之间进行聊天。 用户身份验证和登录正在运行,只是聊天由于某种原因未登录 有问题的代码:

                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)
                    }
            })

在 success block 中找到的 segue 有效,但值 QBChat().isLoggedIn() 总是错误的,如果我尝试通过

向用户 ID 发送消息
QBChat().sendMessage(message: QBChatMessage!)

功能我最终收到“我必须登录才能聊天才能发送”消息 .一定是小问题,是我忽略了什么。

edit: 只是想让你知道这是我第一次使用 quickblox,所以请准确指出我做错了什么

最佳答案

您应该使用 QBChat 的共享实例来进行聊天。

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

同时检查

setAutoCreateSessionEnabled

QBConnection 中的方法。您可以忘记 session 管理。

关于ios - QuickBlox Chat 未登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30779781/

相关文章:

ios - 我的应用程序很简单应用程序崩溃了

java - Web 应用程序登录身份验证和安全问题

ios - 改变非交错浮点的间距

iOS:CoreGraphics - 使用 CGContextClip 和 lineCap = .Round 剪切弧

ios - 在 Swift 中使用 RLMResults 的正确方法是什么?

ios - AVAudioPlayer 实例的音量控制

javascript - 使用身份验证时 Angularjs 路由断断续续

c# - 使用客户端对象模型的 Sharepoint 2010 用户身份验证(Windows 凭据)

IOS 5 无法识别的选择器在 setBackgroundImage 的外观代理处发送

objective-c - iOS 上的 AVAudioRecorder 错误 "playback data format is unsupported"?