How to keep XMPP connection alive in the IOS App when app in background?

747 Views Asked by At

I have create basic chat app with XMPP Server in swift 2 (from this tutorial: http://shubhank101.github.io/iOSAndroidChaosOverFlow/2016/08/Chat-Application-Using-XMPP-Swift-Tutorial). My app is working good. but when my app went into background then my app unable to receive any message from XMPP server. i think this is because of XMPP connection break while entering the app in background.

i have tried to found the help on google for the same but nothing found related to Swift 2

Please help me. if some one put some sample code that would very helpfull for me because i m new to IOS development.

2

There are 2 best solutions below

2
vitalyster On BEST ANSWER

Third-party apps on the iOS are not allowed to keep network connection in background. See Apple guidelines how to avoid background networking.

0
Kashif Sohail EF On

You need to create a background thread to maintain XMPP connection. You can follow this tutorial to see how background thread works. https://thatthinginswift.com/background-threads/