我正在快速创建框架,使用cocoapods我添加了XMPP 框架 ,但不知何故无法连接到我的主机:
我的设置:
class XMPPController: NSObject ,XMPPStreamDelegate{
var XMPP_HOST = "**************";
var userJid:XMPPJID = XMPPJID();
var password = "";
var xmppStream:XMPPStream;
init(jid: String, password: String) {
if let userjabberid = XMPPJID(string: jid) {
self.userJid = userjabberid;
}
self.password = password;
self.xmppStream = XMPPStream();
self.xmppStream.hostName = XMPP_HOST;
self.xmppStream.hostPort = 5222;
self.xmppStream.startTLSPolicy = XMPPStreamStartTLSPolicy.allowed;
self.xmppStream.myJID = self.userJid;
super.init();
self.xmppStream.addDelegate(self, delegateQueue: DispatchQueue.main)
}
和我的连接方法:
func connect() {
if !self.xmppStream.isDisconnected {
return
}
do {
try self.xmppStream.connect(withTimeout: XMPPStreamTimeoutNone);
} catch let err {
print(err);
}
}
和我的委托方法:
func xmppStreamWillConnect(_ sender: XMPPStream) {
print("will connect");
}
func xmppStream(_ sender: XMPPStream, socketDidConnect socket: GCDAsyncSocket) {
print("socket")
}
func xmppStreamDidStartNegotiation(_ sender: XMPPStream) {
print("negotiate")
}
func xmppStream(_ sender: XMPPStream, didReceiveError error: DDXMLElement) {
print(error);
}
func xmppStreamDidDisconnect(_ sender: XMPPStream, withError error: Error?) {
print("disconnected");
}
func xmppStreamDidConnect(_ sender: XMPPStream) {
print("connected");
try! sender.authenticate(withPassword: self.password);
}
func xmppStreamDidAuthenticate(_ sender: XMPPStream) {
print("authenticated");
}
func xmppStream(_ sender: XMPPStream, didNotAuthenticate error: DDXMLElement) {
print("Stream: Fail to Authenticate");
}
在这里,只xmppStreamWillConnect
调用而不调用所有其他委托方法。