1

I have an app that has worked fine in the foreground. I wanted to give it the ability to track locations in the background. However, it is not deferring updates.

The length here is due to trying to answer questions raised in similar posts:

I've gotten the pinfo settings that allow the application to go into the back ground without crashing.

Before going into the background I call:

    [locationManager allowDeferredLocationUpdatesUntilTraveled:CLLocationDistanceMax timeout:CLTimeIntervalMax] ;

But this delegate function gets called immediately:

- (void)locationManager:(CLLocationManager *)manager
 didFinishDeferredUpdatesWithError:(NSError *)error
 {
  if (error)
   {
     NSLog (@"Error deferring updates: %@", error) ;
  }
  return ;
 }

Displaying:

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

Then the location processing continues unabated, with

 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

getting called with every location change while in the background.

I am also seeing this message being written to the log but no idea where it is coming from:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

I am not taking any snapshots explicitly in the app.

(Test device is iPad Air II, IOS 6).

While am I not able to defer location changes?

user3344003
  • 20,574
  • 3
  • 26
  • 62

1 Answers1

0

I think your CLLocationManager object is local object and it will be deallocated immediately after it falls out of scope. You can try to make it a class property and then asynchronous processes like requesting authorization and determining the location will have a chance to run.

Vlad Hudnitsky
  • 1,345
  • 2
  • 11
  • 11