allowDeferredLocationUpdatesUntilTraveled:timeout: still calls didUpdateLocation at 1 hz (iOS 8.3 iPhone 5s)

Has anyone else ran into the issue of telling a location manager to defer updates but still get regular location updates via didUpdateLocations?


I have:

  • Killed all apps from multitasking bar
  • Verified that no other app is using location services
  • Unplugged the device from debugger and MacBook (Verify it is still getting call by logging didUpdateLocations to a file)
  • Made sure that the device supports deferred updates
  • Made sure that 5 fixes in a row are processed within 2 seconds of the previous before deferring
  • Made sure that the distanceFilter is None, the desiredAccuracy is Best, the activityType is Navigation (have also tried OtherNavigation), and that pauseLocationUpdates is YES (Have tried NO too)
  • And potentially more that I cannot remember


Is this method something that the OS decides to do if it needs to and when it does need to it just provides the updates at the a normal interval of 1hz?

Replies

I am also seeing this behaviour. I set the timeout to 60sec, and I get ~60 calls to didUpdateLocations, then I see my update for didFinishDeferred. It appears both are running.


Note: you can't do this when attached to the debugger, Apple's docs specify that Deferred doesn't work then.


That said, I'm still seeing this behaviour (I create new online records for each call to didUpdateLocations)


Have you had any luck?

First, it is important to understand what it means to ask for deferred updates: basically, you are not instructing or ordering the system to defer location updates, but you are only giving the system permission to defer location updates to your app, if it needs to. It is entirely possible and acceptable that the system will not defer location updates to your app. So you app must be ready to handle non deferred updates.


That said, here is how to handle some of the gotchas for deffered updates:

- always check the error returned by the

locationManager:didFinishDeferredUpdatesWithError:
method. You may be getting an error and not starting deferral

- make sure the filter, accuracy and type are set as you think they are

- make sure the allowDeferredLocationUpdatesUntilTraveled: method is not called multiple times. If you call it while deferral is already active, this will cancel the previous deferral and start a new one. A common mistake would be to ask for deferral in didUpdateLocations: but mistakenly ask for it over and over

- make sure your deferral is not cancelled for any reason. Check that you are not getting cancelled in your delegate's

locationManager:didFinishDeferredUpdatesWithError:
method (check for kCLErrorDeferredCanceled)

Hi I have done eveything as mentioned by you and my code is working in iOS 8.4 and below versions but in iOS 9 GM seed version I am getting error.

kCLErrorDeferredFailed - The location manager did not enter deferred mode for an unknown reason.


Its because of this error its not entering the defer mode at all and location updates are firing continously .Its draining the device battery heavily.

Can anyone point the reason for the same?

The documentation states the following for kCLErrorDeferredFailed: This error can occur if GPS is unavailable, not active, or is temporarily interrupted. If you get this error on a device that has GPS hardware, the solution is to try again.


Have you tried subsequently after receiving this error?

Hi, I am attempting to add text to speech functionality to my turn by turn navigation feature in my app. Would I use allowDefferedLocationUpdatesUntilTraveled to determine when I would initiate the text to speech utterance for next upcoming step of the MKDirections request?

Thank you.


Kind regards,


John

I am having the same issue described here on iOS 9. What I have observed is that it gets a few kCLErrorDeferredFailed errors the first few times the deferral is attempted, but the reqauest to defer eventually it succeeds (I get calls on didFinishDeferredUpdates with no error). Once it succeeds, I see successful re-deferral on a regular 2-minute interval, along with batches of location updates with a count as high as 100, but I also still see location updates every second (batch count is 1). I have found several StackOverflow threads on this, and none have clear answers, or if the question does have a clear answer, the discussion thread after the answer ends in "this seems to have broken in ios9".


- I do not have a debugger attached

- I have all of the pertinent configurations set on the CLLocationManager:

clLocationManager.PausesLocationUpdatesAutomatically = false;
  clLocationManager.ActivityType = CLActivityType.AutomotiveNavigation;
  clLocationManager.AllowsBackgroundLocationUpdates = true;
  clLocationManager.DistanceFilter = CLLocationDistance.FilterNone;
  clLocationManager.DesiredAccuracy = CLLocation.AccuracyBest;


- I have requested "always" authorization

- I have called startUpdatingLocation

- I've seen it suggested that when the app is backgrounded, I need to stop and re-startUpdatingLocation, so I have that in there

- I am using the delegate, and taking care not to request deferral if I have a deferral in progress


Any suggestions?