xmppStreamDidConnect 从未在 Swift 中被调用
xmppStreamDidConnect never gets called in Swift
我正在尝试使用 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: "user@chatserver.net")
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) {
我正在尝试使用 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: "user@chatserver.net")
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) {