XMPP Delegate方法连接未触发

时间:2018-04-24 21:43:26

标签: ios xmpp xmppframework

我正在使用xmpp,我发现连接的委托方法永远不会触发。

我有一个openfire服务器正在运行,我可以登录。 我也有Spark运行,我可以登录。

目前,委托方法按此顺序触发。

1. xmppStreamWillConnect
2. socketDidConnect
3. xmppStreamDidStartNegotiation

此后没有任何事情发生。

有谁知道为什么会这样?

这是我的联系..

let jId = XMPPJID(string: "admin@127.0.0.1")
 ChatManager(jID: jId!, host: "127.0.0.1", password: "openfire")

然后在聊天管理器里面..

import Foundation

导入XMPPFrameworkSwift

public final class ChatManager:NSObject {

var stream: XMPPStream!
var jID: XMPPJID
let host: String
let port: UInt16
let password: String

init(jID: XMPPJID, host: String, port: UInt16 = 32876, password: String) {

    self.jID = jID
    self.host = host
    self.port = port
    self.password = password

    // Setup the XMPPStream
    stream = XMPPStream()

    stream.hostName = self.host
    stream.hostPort = self.port
    stream.myJID = self.jID
    stream.startTLSPolicy = .allowed

    super.init()

    stream.addDelegate(self, delegateQueue: DispatchQueue.main)

    connect()
}

private func connect(){
    if !self.stream.isDisconnected {
    }

    let timeoutInterval: TimeInterval = 5.0
    do {
        try stream.connect(withTimeout: XMPPStreamTimeoutNone)
    } catch {}

}

}

扩展名ChatManager:XMPPStreamDelegate {

public func xmppStreamDidSecure(_ sender: XMPPStream) {
    print("Secured...")
}

public func xmppStreamDidStartNegotiation(_ sender: XMPPStream) {
    print("Negotiation Started..")

}

public func xmppStream(_ sender: XMPPStream, willSecureWithSettings settings: NSMutableDictionary) {
    print("Will secure...")
    print("Settings: \(settings)")
}

public func xmppStream(_ sender: XMPPStream, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) {
    print("Recieved trust")
}

public func xmppStreamWillConnect(_ sender: XMPPStream) {
    print("Attempting to connect...")
}

public func xmppStreamDidConnect(_ sender: XMPPStream) {
    print("Connected")
    try! stream.authenticate(withPassword: password)
}

public func xmppStreamConnectDidTimeout(_ sender: XMPPStream) {
    print("Connection timeout")
}

public func xmppStreamWasTold(toAbortConnect sender: XMPPStream) {
    print("Abortion connect")
}

public func xmppStreamDidAuthenticate(_ sender: XMPPStream) {
    print("Stream: Authenticated")
}

public func xmppStream(_ sender: XMPPStream, didNotAuthenticate error: DDXMLElement) {
    print("Stream: Not Authenticated")
}

public func xmppStream(_ sender: XMPPStream, socketDidConnect socket: GCDAsyncSocket) {
    print("Connected socket")
}

}

Console Output

0 个答案:

没有答案
相关问题