I want to track the user location in background, in the purpose to show him an alert when he is close to one of his friend.
So i start with CLLocationManager
. As far as i know their is only one reliable way to let the app know about the location update even if the user reboot the Iphone or kill the app: startMonitoringSignificantLocationChanges
. But the problem is that even inside a city with many wifi, startMonitoringSignificantLocationChanges
fire the DidUpdateLocations
when the user move around 1km and that is really too much for my need
on the other way startUpdatingLocation
is firing DidUpdateLocations
at good interval (even too much because even when the user do not move it's fire quite often DidUpdateLocations
). But startUpdatingLocation
not survive to iphone reboot or app being killed by the user. Also I suspect that even with an accuracy of 100m, startUpdatingLocation
use lot of battery consumption.
So the question: What strategy i can use in my app to track efficiently without draining too much the battery the user location at full time? I need an accuracy of around 100m and if possible an interval between 2.5 - 5 min for each track (i didn't find any option to specify a delay to wait before to catch a new location)
Actually i think to do something like this :
- 2
locationManager
, 1 GPS and 1 Significant Changes - when app start I do with significantChangesLocationManager:
startMonitoringSignificantLocationChanges
andstartMonitoringVisits
- I also call GPSLocationManager
startUpdatingLocation
to retrieve the accurate user position. I set upPausesLocationUpdatesAutomatically(true)
so that the GPSLocationManager will stop by himself soon or late - on
DidUpdateLocations
raise by the GPSLocationManager I start monitoring region enter/exit (100m radius around the obtained latitude/longiture) with significantChangesLocationManager
What do you think of such strategy ?