Question

When the app is in the background and xmpp disconnects because the internet goes down, and if the internet comes back up, when I open the app, the disconnect call is not made so the app doesn't try to reconnect.

If i check the xmppstream is connected it shows as Yes. How can I check if the connection is still alive when I go back to the app?

Currently I am trying a disconnect, and connect each time the app wakes up. But ideal would be to detect disconnection...

Thanks

Was it helpful?

Solution

If you can detect when the app wakes up, then send a ping. If you don't get a reply, reconnect. If the XMPP lib you use has support for Stream Management, especially the stream resumption support, you could use that to pick up the stream.

A better solution would be to have a separate daemon that manages the connection, and stays alive in the background, if that's even allowed on iOS. Also, this XEP might be of interest.

OTHER TIPS

If you're using XMPPFramework (https://github.com/robbiehanson/XMPPFramework), then take a look at XMPPReconnect, which will save you a lot of the hassle of reconnecting.

After the stream has been created, use the following.

xmppReconnect = [[XMPPReconnect alloc] init];
[xmppReconnect activate:xmppStream];
[xmppReconnect addDelegate:self delegateQueue:dispatch_get_main_queue()];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top