0

I am using CLLocationManager in my app and pausesLocationUpdatesAutomatically property is set to YES to save battery.When locations are paused and then I try to restart location updates after specified time interval using startUpdatingLocation method it starts and give 7 to 10 location updates.After that I dont get any further location updates.I call below method to restart updates.

PS:I have already enabled location Background mode in capabilities.

[_locManager startUpdatingLocation];
                if ([_locManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)])
                {
                    _locManager.allowsBackgroundLocationUpdates =YES;
                } 
Desert Rose
  • 3,376
  • 1
  • 30
  • 36
  • @kb920 please read my question again.I am already setting this property to YES. – Desert Rose Apr 13 '16 at 10:08
  • you are using `- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ }` delegate Method right? – Vvk Apr 13 '16 at 10:23
  • @Vvk yes didUpdateLocations is being used. – Desert Rose Apr 13 '16 at 10:25
  • try With Both Method one by one `-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { } -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { }` – Vvk Apr 13 '16 at 10:29
  • The only fix I know (which I found from the duplicate) is to call `startMonitoringSignificantLocationChanges` in the foreground. If you do this then it seems you can call `startUpdatingLocations in the background and get updates indefinitely – Paulw11 Apr 13 '16 at 10:29
  • @Paulw11 I cant force user to bring the app in foreground.Also I want to pause locations if user is not moving significantly to save battery life – Desert Rose Apr 13 '16 at 10:32
  • Believe me, I have tried everything. You don't need to bring the app to the foreground, you just leave significant location monitoring on from the moment your app launches. Then you can start/stop location updates in the background and it will all work. significant location monitoring doesn't use much battery. My test app doesn't even show up in the list of apps using battery in device settings after days of running with just significant location monitoring – Paulw11 Apr 13 '16 at 10:35

1 Answers1

1

Go to project build setting, Under target selected select capabilities - Turn on background mode - check the box location updates.

This can solve your problem i think.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • That property is already.My code does not work once location updates are paused by OS due to pausesLocationUpdatesAutomatically property. – Desert Rose Apr 13 '16 at 10:22
  • When app comes in foreground then is it updating ? – Ketan Parmar Apr 13 '16 at 10:24
  • Yes then it updates. – Desert Rose Apr 13 '16 at 10:24
  • i think that if you set pausesLocationUpdatesAutomatically to yes then it is not allow background execution because of battery saving scenario. – Ketan Parmar Apr 13 '16 at 10:25
  • But it gives 7 to 10 location on starting but after that it doesnt give locations – Desert Rose Apr 13 '16 at 10:26
  • yes it's happens. app take little time to get notification that it's enter in background. you can check it for audio also. if your app plays audio or music and you press home button then your audio pause after 2 or 3 seconds like this location is also take time. – Ketan Parmar Apr 13 '16 at 10:28
  • Follow this http://stackoverflow.com/questions/20187700/startupdatelocations-in-background-didupdatingtolocation-only-called-10-20-time?lq=1 – Akash KR Apr 13 '16 at 10:59
  • I cant rely on significant locations as I need complete accuracy on the data. – Desert Rose Apr 13 '16 at 11:46