3

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?

Jim109
  • 501
  • 6
  • 14

1 Answers1

3

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

Jim109
  • 501
  • 6
  • 14
  • Hi Jim. I have used this article for running app in background it was working great. But the problem was Apple was rejected my app due to enabling that audio mode. So what can I do for this. Please help me. – Karthik Mandava Mar 08 '16 at 06:08
  • The app I was working on was used for in-house deployment - unfortunately I don't believe Apple would accept apps using this work around in the store. – Jim109 Mar 08 '16 at 17:59
  • Yes Apple was not accepting this type of concept. So how can achieve this type and at the same time get approval from Apple. – Karthik Mandava Mar 09 '16 at 04:33
  • If your app doesn't need to run in the background 100% of the time. and it is okay for it to be woken up for only brief intervals, there are two possibilities: you can request for it to be woken up when significant location changes have occurred or to download new content. In these scenarios IOS decides when your app will be woken up, you have no control over it. Perhaps your needs are different than mine and this can be sufficient. Read here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html – Jim109 Mar 09 '16 at 14:14
  • Hi Jim.I have tried this on iOS 10.3 where the app seems to work fine on background.However after the phone is restarted, the app doesn't start automatically.We need to tap the app icon to start it explicitly.Have you checked on iOS 10 by any chance? – iCodes May 04 '17 at 17:13
  • You're right, although I had not elaborated on it, there are two inconveniences with this method - the app doesn't restart automatically after the phone is restarted, and it will stop running if the user manually swipes it out of his tasks. This behaviour is also present in previous versions of IOS. It is possible to execute the app for a brief amount of time immediately after the phone is started, so our solution was to display a notification after reboot to remind the user to fully open the app. – Jim109 May 19 '17 at 14:46
  • Hi @Jim109, this doesn't seem to work for me on iOS 10.3 as I just get this: `Legacy VoIP background mode is deprecated and no longer supported`. Have you had any issues with this or found a way around it? According to other questions on Stack Overflow it's not only deprecated but not working at all any more :/ – simonthumper Jun 19 '17 at 16:51