I'm working on swift and quickblox and I'm trying to have chatting occur between users. 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
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
You should use a shared instance of QBChat for working with chat.
Also check
method in QBConnection. You can forget about session management.