XMPPFramework(Swift)的问题
运行此代码时,没有迹象表明XMPPController已连接到Ejabberd服务器。也没有调用XMPPStreamDelegate方法。好像代码根本就不存在。应该有迹象表明我有联系,不是吗?还有其他人有这个问题吗?这是我的密码。谢谢 XMPPController类:XMPPFramework(Swift)的问题,swift,xmpp,xmppframework,Swift,Xmpp,Xmppframework,运行此代码时,没有迹象表明XMPPController已连接到Ejabberd服务器。也没有调用XMPPStreamDelegate方法。好像代码根本就不存在。应该有迹象表明我有联系,不是吗?还有其他人有这个问题吗?这是我的密码。谢谢 XMPPController类: import Foundation import XMPPFramework enum XMPPControllerError: Error { case wrongUserJID } class XMPPControll
import Foundation
import XMPPFramework
enum XMPPControllerError: Error {
case wrongUserJID
}
class XMPPController: NSObject {
var xmppStream: XMPPStream
let hostName: String
let userJID: XMPPJID
let hostPort: UInt16
let password: String
init(hostName: String, userJIDString: String, hostPort: UInt16, password: String) throws {
guard let userJID = XMPPJID(string: userJIDString) else {
throw XMPPControllerError.wrongUserJID
}
self.hostName = hostName
self.userJID = userJID
self.hostPort = hostPort
self.password = password
self.xmppStream = XMPPStream()
self.xmppStream.hostName = hostName
self.xmppStream.hostPort = hostPort
//self.xmppStream.startTLSPolicy = XMPPStreamStartTLSPolicy.allowed
self.xmppStream.enableBackgroundingOnSocket = true
self.xmppStream.myJID = userJID
super.init()
self.xmppStream.addDelegate(self, delegateQueue: DispatchQueue.main)
}
func connect() {
if !self.xmppStream.isDisconnected() {
return
}
do {
try self.xmppStream.connect(withTimeout: 5)
} catch {
print("ERROR CONNECTING")
}
}
}
extension XMPPController: XMPPStreamDelegate {
func xmppStreamDidConnect(_ sender: XMPPStream!) {
print("Stream: Connected")
try! sender.authenticate(withPassword: self.password)
}
func xmppStreamDidAuthenticate(_ sender: XMPPStream!) {
self.xmppStream.send(XMPPPresence())
print("Stream: Authenticated")
}
}
AppDelegate(用于测试XMPPController)
无论出于何种原因,这都不起作用。您的ejabberd服务器是否正常工作。您可以通过运行./ejabberdctl status来检查ejabberd服务器的状态。另外,你能检查一下ejabberd日志吗。检查ejabberd是否正确配置并正常工作的一个好方法是使用Adium登录ejabberd服务器 检查此部分代码中的端口是否为5222而不是5221
try! self.xmppController = XMPPController(hostName: "192.168.0.33", userJIDString: "admin@192.168.0.33", hostPort: 5221, password: "password")
如果5221正确,则应调用函数connect()
连接
try! self.xmppController = XMPPController(hostName: "192.168.0.33", userJIDString: "admin@192.168.0.33", hostPort: 5221, password: "password")
self.xmppController.connect()