Search code examples
iosswiftcore-locationios13

Why is iOS 13 Core Location sometimes returning locations with coordinate 0,0 in the background?


For context I work on an app that requires authorizedAlways permission. Since the release of iOS 13 we have noticed that ~3-4% of our users are receiving location updates (from didUpdateLocations) that have a coordinate of 0,0 and a horizontalAccuracy of 2500. This seems to only be happening while the app is in a background state.

This is all very confusing given that the app logs all changes to authorization status (using didChangeAuthorization) and at no point do I see any change to a value other than authorizedAlways. That said, based on manual testing I've done it does seem that the app will be notified of a change to authorizedAlways status after a user hits the initial requestAlwaysAuthorization prompt with Allow While Using App. Then when the user backgrounds the app for a little while they are reprompted with two options, Keep Only While Using or Change to Always Allow. The app seems to only get notified of an authorization status change if the user proceeds with Keep Only While Using selection (and the app is notified of a change to authorizedWhenInUse.)

I had a hypothesis that there might be some weird state between the user being prompted for the background use (or the OS determining a prompt is required) and the user actually responding to the prompt, but my testing has pretty consistently shown that in that state the app is simply not receiving any location updates.

I've hit a wall on troubleshooting this and am hoping its just an iOS 13 bug but I've yet to hear of any other apps experiencing this issue. Would greatly appreciate any suggestions on further troubleshooting ideas or simply that your app has experienced this issue as well so I can stop banging my head on it!


Solution

  • This sounds like a bug. If the location is invalid it should have a negative value for horizontalAccuracy but this is definitely an invalid location. Run the CLLocationCoordinate2D through CLLocationCoordinate2DIsValid() or compare it to kCLLocationCoordinate2DInvalid but since you have a positive horizontal accuracy it will probably tell you (incorrectly) that it's valid.

    My guess is the same as yours, that the app has been told it has "Always" permission before the user has actually granted Always from the second prompt and it's somehow receiving bad locations when in the background.

    There's no notification because your app is never supposed to know when it actually has Always permission (presumably to prevent it from waiting until it has Always to start abusing background location).

    Either file a bug with Apple or use a DTS incident. If it's a framework bug you should be re-credited your DTS and get faster support at the same time.

    In the meantime, add extra checks for invalid locations that include the coordinate being 0,0.