XMPPFramework icon indicating copy to clipboard operation
XMPPFramework copied to clipboard

How to keep iphone ios xmpp connection alive while in the background?

Open swathi-gali opened this issue 14 years ago • 9 comments

Xmpp gets disconnected automatically if the app is in the background for more than 3-4 minutes. Is there anyway to keep the connection alive indefinitely or atleast for 30minutes or so?

swathi-gali avatar May 29 '12 14:05 swathi-gali

In the XMPPStreamDelegate, add next method:

/**

  • This method is called after the tcp socket has connected to the remote host.
  • It may be used as a hook for various things, such as updating the UI or extracting the server's IP address.
  • If developing an iOS app that runs in the background,
  • please use XMPPStream's enableBackgroundingOnSocket property as opposed to doing it directly on the socket here. **/
    • (void)xmppStream:(XMPPStream *)sender socketDidConnect:(GCDAsyncSocket *)socket

Simply set the enableBackgroundingOnSocket property on the socket and it should work.

jelledelaender avatar May 30 '12 12:05 jelledelaender

Thanks a lot.. It worked :)

swathi-gali avatar May 31 '12 07:05 swathi-gali

Please share how you did it?

guptatarun84 avatar Aug 10 '15 18:08 guptatarun84

It is not working for me by using enableBackgroundingOnSocket. Please help me. I am stuck.

parthpatel1105 avatar Sep 15 '16 12:09 parthpatel1105

You need an push notification once the user is offline to enable app which is in background and immediately make an connect request to XMPP to get the app alive from background. In my case I used the same mechanism.

guptatarun84 avatar Sep 27 '16 12:09 guptatarun84

If app in background and when we take the app in foreground after 30 minutes then it autoreconnect event doesn't fire, Should XMPP library do this or should we do something else to make connect automatically?

Thanks.

Amitmundra avatar Dec 12 '16 09:12 Amitmundra

Auto reconnect only happens when there is network issue. Incase you need application to wake up from background mode you need to enable push notification through which the application would become active and send a connect request within 30 secs of the whole procedure. Although this is not a full proof solution due to restriction provided by Apple however will work.

guptatarun84 avatar Dec 12 '16 09:12 guptatarun84

Thanks, Anything else that i can do to keep active connection in BG as well?

Amitmundra avatar Dec 12 '16 10:12 Amitmundra

Use iOS default background modes enabled if you have no restrictions with respect to your app requirements :)

guptatarun84 avatar Feb 08 '17 19:02 guptatarun84