Background location updates stop in iOS 16.4

Apple Recommended

  • Thank you for the response! This is very clear.

  • How can I find out if there are plans to fix the issue in the next version?

  • @auroracloud This is not a bug that is waiting to be fixed. The change is by design. Although there could be some fine tuning of the requirements for the property settings in the future to enable background location updates, this change is here to stay, and apps need to be updated to follow the guidance in order to continue background location updates.

Replies

[@Gualtier Malde](https://developer.apple.com/forums/profile/Gualtier Malde) I'm really asking for help! With all due respect, the suggested solutions have not helped. The number of users with the problem is steadily increasing every day. From our data, the increase in the number of users with the problem is not going to stop. Please pay attention to this problem, and maybe something went wrong by design?

@Scott--R did the recommendations above help? Were you able to solve the problem? In my case the recommendations did not help, the reach of users with the problem is growing

Only setting showsBackgroundLocationIndicator to TRUE or YES did not work for me (iOS 16.5.1). I had to unset distanceFilter as well to make it work.

Thank you all for your support and feedback. I've made a lot of tests with IOS versions < 16.4 and IOS versions >= 16.4

The conclusion today is that the best solution was given by Gualtier Malde in this thread, but with one exception: distanceFilter must not be set ONLY (set it to kCLDistanceFilterNone leads to a non-deterministic behavior in 16.4 and upper versions, and stops the location updates or send updates completely erratically.

So with the below code, the location updates in background with IOS > 16.4 work for roughly 5h. After that, it's a mystery why it stops. The debugger spits out nothing ....

  • allowsBackgroundLocationUpdates must be set to TRUE
  • distanceFilter must not be set
  • desiredAccuracy must be kCLLocationAccuracyHundredMeters or better. If you’re using numeric values, it must be set to less than 1000 meters (in my case it's 30 meters)
  • showsBackgroundLocationIndicator to TRUE (when I set it to false ou not set, the behavior got worse)

My app's code now tests which IOS version the device runs and I remove distanceFilter when > 16.4. In the locationManager I also send updates to my backed only every 30s because IOS 16.4 ignores Timer.scheduledTimer ...

At this point of time, I don't know how to do better. I just updated my phone to 16.5 and will run some tests with this version but no hope. It's a shame that with IOS 14.x it works so well ...

If someone has the magic solution, please share.

  • _"So with the below code, the location updates in background with IOS > 16.4 work for roughly 5h. After that, it's a mystery why it stops. The debugger spits out nothing ...." _ Have you been able to find a solution? As you have mentioned, it is totally unclear why the location updates just suddenly stop after a while..

    Any help would be greatly appreciated :)

  • @cedricperret @Jan_S_R @Scott--R @egorbright @nickradar I have lost thousands of users since this change was applied, is there a fix that has worked to keep the updates for longer than 5hrs?

  • @Idamezhim @cedricperret@Scott--R I think i might have found the issue (still testing). When I used the preset 'kCLLocationAccuracyHundredMeters' in order to set the accuracy, I could extend the background-locations indefinitely. But when I changed it to 999 meters (an int-value instead of the preset), it stopped after 5 hours. I changed it back to 'kCLLocationAccuracyHundredMeters' now and I will report back the results.

Add a Comment

My problem was unrelated to the main problem discussed here, so with the piece of code below, any IOS release below or above 16.4 work.

Use case for the example: I print latitude and longitude every 30s.

This code so far worked for +24h like a charm, whatever the device moves or not, whatever the app is in the foreground or in the background, whatever the screen is on or off. Of course you must select 'Location updates' for 'Background modes' in 'Signing & Capabilities' of your project's Target. But this is obvious no :)

class TestLocation: UIViewController, CLLocationManagerDelegate{ @objc var locationManager: CLLocationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() // Configure location manager locationManager.delegate = self // requestAlwaysAuthorization() could be done before in your app, which is the case for me but for the example, I put it here (indeed requestAlwaysAuthorization() MUST be done when the app starts to avoid any crash, if you do some stuff before doing startUpdatingLocation()) locationManager.requestAlwaysAuthorization() locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.allowsBackgroundLocationUpdates = true locationManager.pausesLocationUpdatesAutomatically = false locationManager.showsBackgroundLocationIndicator = true locationManager.startUpdatingLocation() }

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let currentLocation = locations.last(where: { $0.horizontalAccuracy >= 0 }) else { return }

    if let lastUpdateDate = lastLocationUpdateDate, Date().timeIntervalSince(lastUpdateDate) < 30 {
       return
    }
    else{
        print("Latitude: \(currentLocation.coordinate.latitude), Longitude: \(currentLocation.coordinate.longitude)")
        lastLocationUpdateDate = Date()
    }
}

}

Hope it helps

  • Thanks. Maybe this code makes the difference:

    locationManager.pausesLocationUpdatesAutomatically = false
Add a Comment