我正在开发 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/