Background Location Update stops randomly after some time

I have been working on a feature whereby I need to notify the user via local notification once a vehicle is reaching its destination. Accuracy is important here as there are other destinations along the journey so region monitoring and significant change is not applicable after testing and finding that the notification sometimes triggered too late (i.e. after the user passed the destination).


Background Location Update via the standard location update service meets this requirement and several testing confirms the approach. Location monitoring has been constant and notification was triggered when the destination is within a certain distance. To do this, I've turned on:

  • Background Mode (Location Updates)
  • Background Mode (Audio, AirPlay and Picture in Picture, for playing a custom alert when it reaches the destination)


Code wise, I've implemented the standard location update service with the following:

        locationManager.distanceFilter = 10
        locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
        locationManager.activityType = CLActivityType.automotiveNavigation
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.pausesLocationUpdatesAutomatically = false
        locationManager.requestWhenInUseAuthorization()


A delegate in the AppDelegate has also been implemented for didUpdateLocation.

Upon activating, the blue navigation status bar is also showing once I exit my App. Many tests has also affirm that all is working and working well.


The Issue:

Although everything looks good and ready for deploy, we are facing the problem of the background location update stopping after a prolong period of time (about 40 minutes to 2 hours) inconsistently. To test this further, I have also set the location update the night before, seeing the blue navigation bar when I exit, only to find the blue bar is gone when I woke up the next morning (Pretty extreme test, but desperate times call for desperate measures 😀).


I have looked at various Apple documentation and other sources but have not found a reason for this stopping of the service. My best suspicion thus far is that this is something to do with how iOS stops or kills the App due to prolong inactivities with the App. I have ruled out battery life issue as I have been plugged in at times when this occurs. Resource-wise is also less likely since to control the test, I do close off other apps before testing.


My question therefore is, with allowBackgroundLocationUpdates set to true, and pausesLocationUpdatesAutomatically set to false. Is there anything else that I might be missing here that is causing this erratic behaviour of the background location update. If it's an issue of inactivity or lack of significant location change (for the case of when I set it overnight), what can be done to ensure a more consistent keep-alive of the service.


Thank you for reading this long post to a question, just wanted to make sure I explained the situation clearly.

Hope to get some assistance here! Cheers!

Replies

Hi, I have a similar issue. Were you able to find a solution for this?

Hi,

Have you found some solution for this, in my case inconsistency is even 2-12 hours.

Any help would be much appreciated.

Think it is an issue with iOS 12... https://stackoverflow.com/questions/53005174/ios-12-terminates-apps-in-the-background-for-no-reason

Hello,

I am still experiencing this issue on iOS 13. Did anyone find a solution yet?
thought this was an issue with iOS 12 that was fixed, but now it's re-surfacing in iOS 13.7 - 14.1.
other apps (using the same code) on the same device are receiving locations just fine. app is even running and logging activity, but sometimes stops receiving locations.
p.s: permissions are also granted and set to precise, according to the location manager, significant location fires.

I'm observing the same thing on an iPhone XS Max running iOS 16.1 (beta 4). I've checked many times the configuration of my app and of the CLLocationManager. It should always receive updates but sometimes, it stops. When I put the app back into foreground, the updates are received again (the app was not killed). I've not found any pattern: sometimes it happens after 5 minutes, sometimes half an hour or more. It's happening with Low Power Mode enabled and disabled.

Have anyone found a solution?

  • This was ok in iOS 16.0.3 but my app is experiencing this problem with iOS 16.1

Add a Comment