我写了两个函数:
if let stream = xmppStream {
if stream.isAuthenticated(){
println("Logged In")
} else {
println("something is wrong")
}
}
func xmppStreamDidConnect(sender: XMPPStream) {
println("xmppStreamDidConnect")
isOpen = true
var error: NSError?
if (xmppStream!.authenticateWithPassword(password.text, error: &error) ) {
println("authentification successful")
performSegueWithIdentifier("goToBuddyList", sender: nil)
}
}
当我运行我的应用程序时,它会在终端中打印:
something is wrong
xmppStreamDidConnect
authentification successful
即使我输入了真实的凭据,它也会先打印 [出现错误],然后再打印 [身份验证成功]。为什么会这样?
我希望在 [出现问题] 的情况下提醒用户,而不是在 [成功] 的情况下提醒用户,但它也会在成功的情况下提醒用户。
最佳答案
实现 XMPPStreamDelegate 的 xmppStreamDidAuthenticate 和 didNotAuthenticate 方法。
在调用authenticateWithPassword 之后,客户端身份验证肯定会在上述两个函数(xmppStreamDidAuthenticate 和 didNotAuthenticate)中结束,直到那时stream.isAuthenticated() 将返回“0”。
关于ios - Messenger 无法从第一次尝试连接到 XMPP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32198033/