0

The question "Background GPS in iOS. Is this possible?" does not answer this question.

I have a mapping app that uses MKMapView and its built-in location services when the app is active. When the app is in the background, I would still like location updates to be delivered and processed. For that, I'm using CLLocationManager.

I have location updates enabled in the plist file and call startUpdateLocation in the AppDelegate code which also acts as the delegate for CLLocationManager. This is everything mentioned in "Background GPS in iOS. Is this possible?",

When the app is active, everything works okay, getting updates no problem.

But when put in background mode, the little arrow indicating location services are being used comes on, but then disappears after about ten seconds. In this brief time period, the app seems to be able to receive location updates, but when the arrow is gone, no more updates.

Am I doing something wrong? Does MKMapView override what CLLocationManager wants to do?

  • Hi Russell, your question may have already been answered [in this duplicate, or closely related, question](http://stackoverflow.com/questions/5526403/background-gps-in-ios-is-this-possible) – Michael Dautermann Jan 04 '14 at 14:52
  • @MichaelDautermann - Please read the question carefully, you'll see that I am doing everything stated in that reference. Please remove the close request, if you added it. –  Jan 04 '14 at 15:02
  • @Krumelur - Okay, that's what I thought, no need to optimize there. –  Jan 04 '14 at 15:20
  • @Krumelur - have revised the code, still exhibiting the same behaviour - revised the question accordingly. –  Jan 04 '14 at 15:26

2 Answers2

0

To receive location updates in the background, do the following:

  • Make sure to have a started CLLocationManager
  • Make sure to have the following value in your info.plist: "Required background modes" = "App registers for location updates"
  • Avoid doing a lot of complicated things in your locationManager:didUpdateToLocation. In particular, avoid UI operations. Your execution time is limited by iOS, and not all APIs are available.

Everything is well documented, see "Getting Location Events in the Background" in the documentation.

Krumelur
  • 31,081
  • 7
  • 77
  • 119
0

Make sure "Background App Refresh" is enabled in your settings. You can check this programmatically by using backgroundRefreshStatus of UIApplication.

Yimin Rong
  • 1,890
  • 4
  • 31
  • 48