Open eduhcano opened 5 years ago
you have to add xmppStream delegate
xmppStream.addDelegate(self, delegateQueue: DispatchQueue.main)
Hi @gotamafandy , yes, I added it just after didfinishLaunchingWithOptions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
stream.addDelegate(self, delegateQueue: DispatchQueue.main)
....
@eduhcano sorry i didn't see that :), do you also implement XMPPStreamDelegate
somewhere in your code?
No problem, thanks for your help :)
Yes, I made AppDelegate a delegate for XMPPStreamDelegate
.
In order to investigate, I have created two basic projects, one in Objective C, which connects smoothly and the other in Swift.
In the Swift project, XMPP calls the delegate func xmppStream (_ sender: XMPPStream, willSecureWithSettings settings: NSMutableDictionary)
(I don't know why in ObjC don't) then, in my delegates, I complete the security functions and then, debugging, I see that Xmpp Framework calls [multicastDelegate xmppStreamDidConnect:self];
However my delegate never triggers.
I've attached the projects.
xmpp_lab.zip
@eduhcano try changing your pod into pod 'XMPPFramework/Swift'
and update all your XMPPStreamDelegate methods, e.g:
from:
func xmppStreamWillConnect(sender: XMPPStream!) {
print("will connect")
}
into:
func xmppStreamWillConnect(_ sender: XMPPStream) {
print("will connect")
}
i've updated the delegate on your code and it's working
YES!! now works perfect! 👯♂️ As I wasn't importing the Swift extensions, the compiler marked as incorrect the method declaration with the underscore. I am very grateful to you @gotamafandy, you have helped me a lot.
@gotamafandy I'm really sorry for abusing your kindness, but I'm facing the same problem trying to connect to a room. I've declared my delegate as:
extension XMPPRoom: XMPPRoomDelegate{
public func xmppRoomDidJoin(_ sender: XMPPRoom) {
print("room did join")
}
}
Connection happens and the framework calls the delegate with [multicastDelegate xmppRoomDidJoin:self];
But my delegate implementation never triggers, I've been trying to find out since yesterday what is the correct method declaration without success.
I've made an example project again. Xmpp_swift.zip
hi @eduhcano sorry for late reply, have you resolve the issue?
No worries @gotamafandy, you helped me a lot. The truth is that I didn't get to activate the room join event, so I made a workaround and checked the connection status when I need to know it.
I am trying to connect to my chat server in a Swift app, but the didConnect delegate method never gets called. I have created a basic app in Objective C and I can connect and authenticate in my chat sever without problems.
In the Swift project I tried to connect with the code:
I’ve debugged XMPPFramework and in the method
- (void)handleStreamFeatures
a call to the delegate is executed :[multicastDelegate xmppStreamDidConnect:self];
I’ve watched the multicastDelegateObject and has a node with reference to my delegate, and to OS_dispatch_queue_main, but after execution my xmppStreamDidConnect method isn’t executed.