Search code examples
iosbackground-processkeep-alivelivechat

How do iOS chat apps keep running in the background?


I have always coded for Android, and now I'm looking to expand my knowledge to iOS development; so I'm really new at this, please be patient.

I understand that only a small group of apps are allowed to run indefinitely in the background. Those are VoIP, Music players and location tracking apps.

I want to write a chat app using the XMPP framework. Everything is fine until the user puts the app in the background, in which case, the app will stay connected for about ten minutes to then be killed by the system and therefore the user won't be able to receive new messages.

I am aware of hacks to keep the app alive. Hacks such as defining it as a music playing app in the info.plist file and then just play some empty sound indefinitely. But I'm also aware that Apple will reject the app when it's time to publish to the App Store.

So, normally, how do other apps do it? How can other chat apps stay alive in the background to receive new messages from the servers? Apps like Google Hangouts, IM+ and such?


Solution

  • The iOS operating system allows for the existence of something called a PUSH NOTIFICATION

    There exists hundreds of tutorials online which teach you how to implement the notification code and how to respond accordingly when you receive such a message! Image http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

    Check this link out for an in-depth tutorial on push notifications! http://maniacdev.com/2011/05/tutorial-ios-push-notification-services-for-beginners