1
votes

We're trying to constantly track the user's location using CoreLocation (enterprise app, so user experience and battery usage is not an issue).

We get good results while the app is in the background using a CLLocation with startUpdatingLocation and a the "location" key in the Info.plist for background tasks.

However in testing it seems that after a few hours the app is terminated and we stop getting updates.

We've tried calling startMonitoringSignificantLocationChanges in applicationWillTerminate in the hope that would still work while the app is terminated, but that doesn't seem to work.

Basically we want a way to constantly keep the app receiving startUpdatingLocation updates, and not have it killed in the background.

3

3 Answers

0
votes

The short answer is, there's no way to prevent iOS from terminating your app if it needs memory, and your app is in the background.

That said, are you positive that your app is really being killed? Past threads about location behavior when the app is in the background have mostly centered on why the app won't die (or at least why location services updates continue past the point where the developer thinks he or she has stopped them). I haven't seen a lot of cases, personally, where individual apps are killed in the background at all, so I'm a bit surprised that yours is dying so reliably. Have you checked your app for memory leaks? I wonder if you're leaking yourself out of memory.

0
votes

You need to register for significant location changes with this call: startMonitoringSignificantLocationChanges. As written in the docs: "If you leave this service running and your application is subsequently suspended or terminated, the service automatically wakes up your application when new location data arrives."
If it's enough to execute code in the background, register for regionChangeMonitoring. Again from the docs: "Regions associated with your application are tracked at all times, including when your application is not running. If a region boundary is crossed while an application is not running, that application is relaunched into the background to handle the event."

0
votes

I'm developing an application with the same your requisites. I have made some tests with instruments and the Memory monitor module, not actually with a long run like you (I have tested the app just for 30 minutes), but I noticed that it regularly goes in background mode without be suspended. Notice that it is not suspended only if UIBackgroundMode is set to "location" or one of other allowed values, and if startUpdatingLocation has been called.

The OS usually automatically closes the applications in suspended state in least recently used order, but since this kind of configuration, your app should not be closed. The only reason that I could image to be closed by the OS is if it's in a very low memory condition and it has no other possibilities to free memory, or if your app has crashed of course. Please see my post here. Your question is now 4 month old, did you find the problem?