Continuously run an IOS app in the background even after sleep or reboot

Jim109 picture Jim109 · Jan 20, 2015 · Viewed 6.9k times · Source

I need to run an iPhone app in the background continuously so that it can respond to events thrown by CTCallCenter and CTTelephonyCenter. I have been using Private API's but can not jailbreak the phone. By using Location and VOIP background modes, I have been able to run in the background past the IOS 10 minute limit. Everything works well as long as the iPhone remains active, however, when the system has been asleep for too long or rebooted, the application no longer receives events thrown by CTCallCenter and CTTelephonyCenter and stops regularly logging its background tasks. It can however receive location events at which time it runs for a short period then is suspended again.

How can I ensure that the app always remains in an active background state, even after sleep or reboot?

Answer

Jim109 picture Jim109 · Feb 2, 2015

I have been able to keep the app running after sleep without jailbreaking the phone or using private API's. As I suspected it was possible, after all, I've seen other apps do it.

The key to keep the app awake is to play an empty background audio in an infinite loop. Permissions required are VOIP and Audio. Even if the phone is asleep for hours the background loop will keep executing.

The second part of this article describes this approach: http://hayageek.com/ios-long-running-background-task/

Here is a link to an example iPhone app: http://hayageek.s3.amazonaws.com/downloads/ios/LongRunningBackgroundTask.zip

Edit: To lower battery usage it is possible to run the audio for brief intervals only in applicationDidEnterBackground, which will reset the value of UIApplication.sharedApplication().backgroundTimeRemaining