deferredLocationUpdatesAvailable returns NO in iOS

2019-01-11 15:19发布

问题:

I am trying to use some CoreLocation features, and I am running into problems with deferred location updates.

For some reason when the app was updated for iOS 10 deferredLocationUpdatesAvailable returns NO always. I am testing on an iPhone 6s, so I know that the device is capable of using GPS features.

I tried using this to debug:

[CLLocationManager deferredLocationUpdatesAvailable]

I can't figure out if this is an issue with iOS 10 or if I have something set incorrectly.

In this method:

- (void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error {
    self.deferringUpdates = NO;
    NSLog(@"DEFERRING Error: [%@]", error);
    if (error) {
        [[LocationManagerClient alertWithMessage:error.localizedDescription andTitle:error.domain] show];
    }
}

I end up logging this error:

DEFERRING Error: [Error Domain=kCLErrorDomain Code=11 "(null)"]

Has anyone else run into this problem with iOS 10 or have any idea what is going on?

Edit: This is how I am setting the distance filter

- (void)configureForApplicationWillResignActive {
    [_locationManager setAllowsBackgroundLocationUpdates:YES];
    [_locationManager setPausesLocationUpdatesAutomatically:NO];
    [_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [_locationManager setDistanceFilter:kCLDistanceFilterNone];   // use distance filter
    [_locationManager requestAlwaysAuthorization];
}

- (void)configureForApplicationDidBecomeActive {
    [_locationManager setAllowsBackgroundLocationUpdates:YES];
    [_locationManager setPausesLocationUpdatesAutomatically:NO];
    [_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [_locationManager setDistanceFilter:kCLDistanceFilterNone];   // use distance filter
    [_locationManager requestAlwaysAuthorization];
}

回答1:

I have already filed a Radar (28303779) with proof of concept sample code - also contains the wording from the radar. I have also opened a dev forum post and it appears a lot of engineers are facing the same problem. deferredLocationUpdatesAvailable() is also returning false in iOS 10. Seems like apple has intentionally turned off the functionality.

Update

My Bug Report got closed saying 'it works as intended'. I suppose Apple does not intend to fix it and it was mistakenly taken out without deprecation first.



回答2:

I looks like this is a bug in iOS 10

We should all file radars to get it fixed, please dupe mine: openradar.appspot.com/radar?id=4927958787555328



回答3:

It seems like it is a "bug". (reproduced on iOS11 and iOS12, iPhone 7, iPad mini 4 cellular)

CLLocationManager.deferredLocationUpdatesAvailable() always returns false, so code for deferred updates never run. However, when app is in the background and Location manager delivers positions via locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]), those positions are delayed as if deferred mode was enabled.

I am thinking that deferred API is there just for compatibility reasons with old apps, and new apps don't need to worry about it at all.