5

I am trying to use the new iOS 6 feature of deffered location updates but keep on getting this error :

didFinishDeferredUpdatesWithError :Error Domain=kCLErrorDomain Code=11 "The operation couldn’t be completed. (kCLErrorDomain error 11.)"

I am using the following code:

- (DeviceAPI *) init
    {
     locationManager = [[CLLocationManager alloc] init];
     [locationManager setDelegate:self];
     [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
     [locationManager startUpdatingLocation];
     [locationManager allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)100000     timeout:(NSTimeInterval)100000];

    return self;
 }

And this callback function :

- (void)locationManager:    (CLLocationManager *)   manager
                        didFinishDeferredUpdatesWithError:(NSError *)error
{
    NSLog(@"didFinishDeferredUpdatesWithError :%@", [error description]);
}

Any help?

Mathias
  • 15,191
  • 9
  • 60
  • 92
user1762103
  • 51
  • 1
  • 2
  • Error 11 for `kCLErrorDomain` is `kCLErrorDeferredFailed`. See documentation [here](https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CoreLocationConstantsRef/index.html#//apple_ref/c/tdef/CLError). – Pang Mar 17 '15 at 10:38
  • I found this looking for iOS 10 http://stackoverflow.com/questions/39498899/deferredlocationupdatesavailable-returns-no-in-ios-10 – Mc Gz Mar 25 '17 at 00:27

5 Answers5

8

According to the Apple Developer Forums for the iOS 6.0 SDK, deferred location updates are only available:

  • on iPhone 5 hardware
  • running iOS 6.0 or higher
  • desired accuracy set to kCLLocationAccuracyBest or kCLLocationAccuracyBestForNavigation because this requires a GPS chip. An iPad without cellular data does not have a GPS Chip.
  • call the "startUpdatingLocation" method
  • wait for location updates to come in at approximately 1 per second
  • then begin deferring updates

See: https://devforums.apple.com/message/751974#751974

See docs: allowDeferredLocationUpdates(untilTraveled:timeout:)

So sounds like you need iPhone 5 hardware, and to wait for location updates to come in at 1Hz.

Additionally, as another poster mentioned, you'd need to implement the locationManager:didUpdateLocations: method in your delegate.

The most common place to call this [allowDeferredLocationUpdates] method is in your delegate’s locationManager(_:didUpdateLocations:) method. After processing any new locations, call this method if you want to defer future updates until the distance or time criteria are met. If new events arrive and your app is in the background, the events are cached and their delivery is deferred appropriately.

From docs. I've added notes inside [].

mfaani
  • 33,269
  • 19
  • 164
  • 293
Jen Leech
  • 136
  • 1
  • 4
0

Did you set location in your info.plist UIBackgroundModes field?

  • Yes I have... I have also found out that [CLLocationManager deferredLocationUpdatesAvailable] returns FALSE. This occurs both on ios6 simulator and iPhone 4 IOS6 device. any thoughts? – user1762103 Oct 31 '12 at 21:01
0

In my testing I have found that deferred updates only work in iOS 6.0.1 or greater, but not 6.0. I tested on 2 phones 1 which I updated and 1 which I left using 6.0 for testing reasons. I believe this is the reason why the simulator doesn't work and if your phone isn't updated yet it is likely why that isn't working either.

Also make sure you implement

– locationManager:didUpdateLocations:

rather than the now deprecated

– locationManager:didUpdateToLocation:fromLocation:

as it is required for use with deferred location updates.

Mike Gottlieb
  • 966
  • 6
  • 11
0

Before you call allowDeferredLocationUpdatesUntilTraveled:timeout: set the distance filter to kCLDistanceFilterNone, then it will work.

Paul King
  • 1,881
  • 20
  • 23
-1

I found this description in one Framework sample for [CLRegion initCircularRegionWithCenter] call:

"If the overlay's radius is too large, registration fails automatically, so clamp the radius to the max value."

vedrano
  • 2,961
  • 1
  • 28
  • 25