Background location tracking on iPad fails

My app needs to track background location for a period of several hours while the user is using it, and we want to allow the user to switch apps or lock their phone while this is happening. We don't need to track location permanently and because of this, we don't want to request the "Always allow" permission.

The app requests "While in use" permission and it has the "Location updates" background mode enabled. The CLLocationManager has 'allowsBackgroundLocationUpdates' set to true, 'pausesLocationUpdatesAutomatically' false, kCLLocationAccuracyBest, kCLDistanceFilterNone, and .fitness for the activity type (we expect the user to be walking).

The app also initializes a CLBackgroundActivitySession while it is tracking location and invalidates it when done.

When I test this combination on my iPhone, it works fine. I get location tracking in the background for as long as I need it, regardless of what else I do with the phone.

However, my customer says it doesn't work for him. He is using a Wifi-only iPad with an external GPS receiver called "BadElf GPS Pro". He says that the external GPS receiver works fine with other apps on his iPad. With my app, he gets background location tracking only for a short time, and then it stops.

The app does monitor the "locationManagerDidPauseLocationUpdates" callback and posts a local notification if it gets called, but it doesn't get called. I've also confirmed with him that he is not force-quitting the app and the app is not otherwise being terminated by iOS.

Is there something I'm missing?

"and then it stops" is quite generic and could mean many things, from your app crashing, to some threading issue that is taking too long to process the location data in didUpdateLocations() callback.

Using an external GPS is identical to an internal GPS as far as your app is concerned except for the .sourceInformation.isProducedByAccessory property of the CLLocation will be set to TRUE.

Various reasons I can think of what could be happening are:

  • app is crashing
  • app is being terminated by the system because of resource shortage. Perhaps this is an older iPad with limited memory
  • you are not being able to process didUpdateLocations() fast enough - either due to the iPad, or the GPS device is sending some unexpected location data that is causing your code to take longer (or even crash)
  • your app is depending on a network connection to do something (sending the locations to a server perhaps). WiFi only iPads will have their WiFi powered down if there isn't a foreground app using network resources continuously. Perhaps that's what happens, and your app is stopping and causing a crash or slow processing because it can't access the network

These are some things I can think of. You can start by debugging your app on this particular setup to see if it fits in one of the above scenarios. And perhaps you'll find out about some other fail scenarios as well.


Argun Tekant /  DTS Engineer / Core Technologies

Background location tracking on iPad fails
 
 
Q