9

I have an app which continually tracks the device location in background. This worked pretty well in ios 11.4 where I could let run the app in background for days while still doing other stuff in foreground.

Now with ios 12 the app does stop running after some time when the device is let alone.

LocationManager is intialized as follows:

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
locationManager.startUpdatingHeading()
locationManager.allowsBackgroundLocationUpdates = false
locationManager.pausesLocationUpdatesAutomatically = false
if #available(iOS 11.0, *)
{
    locationManager.showsBackgroundLocationIndicator = true
} 
locationManager.distanceFilter = prefs.getDoubleFromString(Prefs.PREF_DISTANCE_FILTER, defaultVal: 2.5)

When the user decides to start tracking

locationManager.allowsBackgroundLocationUpdates = true

is set.

The app has the "Always" privilege set for location service.

Any idea what changed in ios 12 ?

Michael Konz
  • 503
  • 1
  • 3
  • 20
  • You have background updates set to `false` – Paulw11 Sep 27 '18 at 10:01
  • Yes, initially. But as I pointed out the user decides at some point to activate the full tracking functionality and then this parameter is set to `true` – Michael Konz Sep 27 '18 at 10:09
  • You've said **app has the "Always" privilege set for location service**, but your code only triggers `requestWhenInUseAuthorization`. Are you sure user has allowed `always` privilege. – Swapnil Luktuke Sep 27 '18 at 10:09
  • You need to show all of the relevant code for us to be able to help you. – Paulw11 Sep 27 '18 at 10:11
  • Yes, "Always" is set in the app Settings. @Paulw11: I showed in my code snippet already that the parameter is set later. Not sure what other parts would be relevant. Please keep in mind, that this is code worked perfectly well under ios 11.4.x. – Michael Konz Sep 27 '18 at 10:45
  • Hi @MichaelKonz I've created an demo app to demonstrate the problem. It's now in test modus: https://github.com/flitsmeister/ios-cllocationmanager-background – Sjoerd Perfors Oct 15 '18 at 12:50

2 Answers2

4

This seems to be a bug since iOS 12 that apps will get terminated in background for no decent reason. I've filled in a bug report.

See for more information and a demo project to demonstrate the problem here: iOS 12 terminates apps in the background for no reason

Bug is fixed in iOS 12.2 beta 2 (16E5191d)

Sjoerd Perfors
  • 2,317
  • 22
  • 37
1

I have this question too, and I try to turn off the "Do Not Disturb" last night, background location service works fine.

So, the "Do Not Disturb" mode can stop location service?

Any other way to avoid location service stopping except turn off "Do Not Disturb"?

AntScript
  • 513
  • 5
  • 6
  • Never had "Do not Disturb" turned on the iPad I use for testing. I implemented some logging to see when and why the app terminates. But of course it didn't since then... I also changed it to `locationManager.requestAlwaysAuthorization()` and `locationManager.allowsBackgroundLocationUpdates = true` at app start. – Michael Konz Oct 01 '18 at 09:36