Location and App Lifecycle - iOS

How to use location manager in different lifecycle (Foreground, Background) of the app.
  1. LifeCycle
  2. Enable Location in background
  3. Refresh Location with high frequency


According to official documentation, the app can be in four different states:

Enable Location in background

As soon as the app enters the suspended state (in other words the app is still resident in memory but is no longer executing code) the updates will stop. If location updates are required even when the app is suspended (a key requirement for navigation based apps), continuous background location updates must be enabled for the app. When enabled, the app will be woken from suspension each time a location update is triggered and provided the latest location data.

To enable continuous location updates is a two-step process beginning with addition of an entry to the project Info.plist file. This is most easily achieved by enabling the location updates background mode in the Xcode Capabilities panel as shown in :

Background Mode

Within the app code, continuous updates are enabled by setting the allowsBackgroundLocationUpdates property of the location manager to true:

myLocationManager.allowsBackgroundLocationUpdates = true

To allow the location manager to temporarily suspend updates, set the pausesLocationUpdatesAutomatically property of the location manage to true.

myLocationManager.pausesLocationUpdatesAutomatically = true

See the reference Apple documentation

Refresh Location with high frequency

Some use cases or situations are more demanding on position collection or geofence detection. To complete standard mode the SDK provides a high frequency location mode. This mode allows to retrieve a maximum of location when activated. It also assures a more accurate detection of geofence crossings. This mode can be set with:

WoosmapGeofencing.shared.setModeHighfrequencyLocation(enable: true)

When activated, locations are updated every 10 meters but for battery and performance optimisation, no POI detection, Distance calculations or zone classification are done over the collected locations. This mode can be used in background or even whne the app has been killed but it generates high battery consumption. Therefore, it should be used for proper use cases, when user is well aware of the tracking and be turned off as soon as high frequent positioning is not usefull anymore.