Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
911 views
in Technique[技术] by (71.8m points)

xcode - How to work with deferred location iOS 6?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 [].


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...