Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager didUpdateToLocation not being called after some time

I am trying to record a users location over time. If the user is on the move it works fine and the delegate method didUpdateToLocation is invoked reliably.However if the user is stationary and the app is running in the background then after some time, the delegate method is no longer invoked. To restart it, the app needs to be bought into the foreground. Once it is active the delegate method is invoked reliably again.

I initially thought that this could be due to the fact that the CLLocationManager object was declared within a ViewController, so I changed it to be declared within the AppDelegate but that did not help either.

I have also experimented with the distanceFilter property to no avail. I am currently setting it up using the following code from within a View controller. Note that the object itself is declared and initialized in the AppDelegate object.

 app.locationManager.delegate = self;
    app.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    app.locationManager.distanceFilter = kCLDistanceFilterNone;
    [app.locationManager startUpdatingLocation];

Has anyone else run into this issue? Any pointers would be appreciated. I have been struggling with this for a few days now.

like image 905
Bharat Ahluwalia Avatar asked Dec 06 '22 09:12

Bharat Ahluwalia


1 Answers

iOS 6 introduces the CLLocationManager property pausesLocationUpdatesAutomatically. It needs to be set to NO when you set up your CLLocationManager, as described here: http://www.stackoverflow.com/a/12781634/700769

like image 97
beev Avatar answered Jan 26 '23 01:01

beev