[英]QuickBlox Chat not logging in
我正在研究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,如果我嘗試通過以下方式向用戶ID發送消息
QBChat().sendMessage(message: QBChatMessage!)
功能我最終收到“必須登錄才能聊天”消息。 這一定是一個小問題,原因是我忽略了某些東西。
edit:
就是這樣,您才知道這是我第一次使用quickblox,因此請准確說明我做錯了什么
您應該使用QBChat的共享實例進行聊天。
QBChat.instance().addDelegate(self)
QBChat.instance().loginWithUser(currentUser)
還要檢查
setAutoCreateSessionEnabled
QBConnection中的方法。 您可以忘記會話管理。
請檢查我在Objective-C語言上工作的代碼。
欲了解更多信息,請檢查
// 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;
}];
或這樣做
// 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.