I\'m somewhat a beginner to iPhone app development, but I\'m trying to make an app that basically updates your location every once a while when it\'s not in the foreground,
Read the background location documentation on the Apple site here
One option you have is to declare your app as requiring continuous location updates.
An application can declare itself as needing continuous background location updates. An application that needs regular location updates, both in the foreground and background, should add the UIBackgroundModes key to its Info.plist file and set the value of this key to an array containing the location string. This option is intended for applications that provide specific services, such as navigation services, that involve keeping the user informed of his or her location at all times. The presence of the key in the application’s Info.plist file tells the system that it should allow the application to run as needed in the background.
This will have the desired result in that your app will be able to track where the user walks, however you need to be aware that this is the most power hungry option and it is generally regarded as the least desirable option. However if you are trying to track someone's walk, this is the sort of thing you need to do.
HOWEVER. You say you only want to get updates every 10 mins or so. In that case you are best NOT to use this strategy and instead use significant location updates. These WILL restart your app if it is closed but as you say, they are not very accurate. The trick to making them better is to start normal location updates as soon as the app gets the significant location update and you should get enough time for that to improve your location (by sending you some more updates) before the app is suspended again.
It won't be perfect, but it will be better than just using significant (ie cell tower) changes.
You Could just use startUpdatingLocation
but just make sure that your CLLocationManager
's properties are set :
Use distanceFilter
wisely : instead of checking for location update every X minutes , just tell the Location manager to update you every 200/300 meters (depends if your user is on-foot , or driving).
desiredAccuracy
should be as well set to about 100 meters (look at the constants declared in the header files) so your app won't drain the battery..
Your app will not be relaunched if killed , but as long as it stays in the background , it (meaning , the Location Manager's delegate) will continue to receive locationManager:didUpdateToLocation:fromLocation:
.
Hope that helps.