我正在研究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)
}
})
成功块中找到的segue起作用,但是QBChat()。isLoggedIn()的值始终为false,如果我尝试通过
QBChat().sendMessage(message: QBChatMessage!)
功能我最终收到“必须登录才能聊天”消息。这一定是一个小问题,原因是我忽略了某些东西。
edit:
只是为了让您知道这是我第一次与quickblox合作,所以请准确了解我做错了什么
您应该使用QBChat的共享实例进行聊天。
QBChat.instance().addDelegate(self)
QBChat.instance().loginWithUser(currentUser)
还要检查
setAutoCreateSessionEnabled
QBConnection中的方法。您可以忘记会话管理。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句