我正在尝试使用XMPPFramework连接到Swift应用程序中的聊天服务器,但是永远不会调用didConnect委托方法。我在Objective C中创建了一个基本的应用程序,我可以在聊天服务器上连接和验证没有问题。
在Swift项目中,我尝试连接代码:
class AppDelegate: UIResponder, UIApplicationDelegate {
var stream:XMPPStream = XMPPStream()
var reconnect:XMPPReconnect = XMPPReconnect()
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
stream.addDelegate(self, delegateQueue: DispatchQueue.main)
stream.myJID = XMPPJID(string: "[email protected]")
reconnect.activate(stream)
do {
try stream.connect(withTimeout: XMPPStreamTimeoutNone)
}
catch let err{
print("error occured in connecting\(String(describing: err.localizedDescription))")
}
return true
}
我已经调试了XMPPFramework并且在方法中--(void)handleStreamFeatures
执行了对委托的调用:
[multicastDelegate xmppStreamDidConnect:self];
我已经观看了multicastDelegateObject并且有一个节点引用了我的委托和OS_dispatch_queue_main,但是在执行之后我的xmppStreamDidConnect
方法没有被执行。
正如在这个Github Issue,中描述的那样,问题是方法声明。我的xmppStreamDidConnect
需要一个下划线,根本问题是,如果你不导入swift扩展,编译器会将该声明标记为不正确,尽管它有效。所以为了解决我的问题,我需要导入pod'XMPPFramework / Swift'并将方法声明更改为
func xmppStreamDidConnect(_ sender: XMPPStream) {