Location tracking stops after a while when app is in the background

Switch to significant location updates when the app moves to background. iOS will unload the app if it keep alive in the background indefinitely.

locationManager.pausesLocationUpdatesAutomatically = false

Reduce Accuracy

Set the desiredAccuracy property of the location manager object

self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation

You can use one of the CLLocationAccuracy constants

IMPORTANT

By default, standard location updates on iOS devices run with an accuracy level of best. Change these settings to match your app’s requirements. Otherwise, your app will unnecessarily waste energy.


Auto-Pause

Set the pausesLocationUpdatesAutomatically property of the location manager object to true

self.locationManager.pausesLocationUpdatesAutomatically = true

IMPORTANT

For apps that have in-use authorization, a pause to location updates ends access to location changes until the app is launched again and able to restart those updates. If you do not wish location updates to stop entirely, consider disabling this property and changing location accuracy to kCLLocationAccuracyThreeKilometers when your app moves to the background. Doing so allows you to continue receiving location updates in a power-friendly manner.


Allow background updates

Set the allowsBackgroundLocationUpdates property of the location manager object to true

self.locationManager.allowsBackgroundLocationUpdates = true

Apps that want to receive location updates when suspended must include the UIBackgroundModes key (with the location value) in their app’s Info.plist file and set the value of this property to true. The presence of the UIBackgroundModes key with the location value is required for background updates


Specify an Activity Type

Set the activityType property to let Core Location know what type of location activity your app is performing at a given time

self.locationManager.activityType = .automotiveNavigation 

You can use one of the CLActivityType cases


Defer Location Update

On supported devices with GPS hardware, you can let the location manager defer the delivery of location updates when your app is in the background. For example, a fitness app that tracks the user’s location on a hiking trail can defer updates until the user has moved a certain distance or a certain period of time has elapsed.


  • Energy Efficiency Guide for iOS Apps - Location Best Practices
  • GettingLocationWhenSuspended