Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to startMonitoringSignificantLocationChanges?

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, so that I can then map where a person's been when he/she launches an app. I thought I could use startMonitoringSignificantLocationChange, because that works when the application is in the background, but it turns out that that's very inaccurate. I would really like to be able to set a time interval, so for instance, every 10 minutes the location will be updated, but I have no clue how to go about that. Any ideas?

like image 559
evanskis Avatar asked Feb 26 '23 05:02

evanskis


1 Answers

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.

like image 169
Roger Avatar answered Mar 08 '23 12:03

Roger