Alternative to startMonitoringSignificantLocationChanges?

I'm starting a bit of developing applications for the iPhone, but I'm trying to create an application that updates your location anyway when it is not in the foreground, so I can then match where the person was when he launches the application. I thought I could use startMonitoringSignificantLocationChange because it works when the application is in the background, but it turns out that it is very inaccurate. I would really like to set the time interval, for example, every 10 minutes the location will be updated, but I do not know how to do it. Any ideas?

+4
source share
2 answers

Read the background location documentation on Apple's website here.

One option is to declare your application as constantly updating location.

An application may declare itself as the need for a constant background Update location. An application that needs regular location updates, both in the foreground and background, should add the UIBackgroundModes key to its Info.plist and set the value of this key to an array containing the location string. This parameter is intended for applications that provide specific services, such as navigation services related to the preservation of the user informed about his whereabouts at all times. The presence of a key in the application file Info.plist 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 application can track where the user is going, however you need to know that this is the most energy-intensive option, and it is usually considered the least desirable. However, if you are trying to keep track of someone coming, this is what you need to do.

HOWEVER . You say you want to receive updates every 10 minutes or so. In this case, you should NOT use this strategy and use significant location updates instead. These WILL reload your application if it is closed, but as you say, they are not very accurate. The trick to improving them is to start a normal location update as soon as the application receives a significant location update, and you should get enough time to improve your location (by sending you a few more updates) before the application is paused.

This will not be ideal, but it will be better than just using significant (i.e., mesh) changes.

+5
source

You can use startUpdatingLocation , but just make sure your CLLocationManager properties are CLLocationManager :

  • Use distanceFilter wisely: instead of checking for a location update every X minutes, just tell the location manager to update you every 200/300 meters (depending on whether your user is standing or driving).

  • desiredAccuracy should also be set to about 100 meters (look at the constants declared in the header files) so that your application does not drain the battery.

Your application will not be restarted if it is killed, but as long as it remains in the background, it (which means the delegate of the location manager) will continue to receive locationManager:didUpdateToLocation:fromLocation:

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1338190/


All Articles