CLLocationManager when the application is in the background

My question is: is CLLocationManager running and my application inactive?

+6
source share
4 answers

Yes, if the CLLocationManager first called the startUpdatingLocation method, and Required Background Modes -> App registers for location updates added to the AppName-Info.plist file

+9
source

Yes it is possible. You have two options for handling distribution service events when your application is paused, which can be found in the article: Getting the current location of users . As noted:

There are two different services that you can use to get the current location of users:

  • The standard location service is a custom, universal solution that is supported on all versions of iOS.
  • The significant location change service offers a low-power location service for mobile radio devices. This service is only available in iOS 4.0 and later and may also launch an application that is paused or not running.

Also, as noted at the bottom of this article in the section "Receiving Location Events in the Background":

  • If your application needs location updates, if the application is in the foreground or in the background, there are several options for this. Your preferred option is to use a meaningful location service to wake up your application at appropriate times to handle new events. However, if your application needs to use the standard location service, you can declare your application as necessary for determining the location of the background.
  • An application should request location services only if the lack of these services impairs its ability to operate. In addition, any application that requests background location services should use these services to provide tangible benefits to the user. For example, a turn-by-turn navigation application will be a likely candidate for background location services because of the need to track a user's position and notify when it is time to make the next turn.
+2
source

There are several important subtleties with this (starting with iOS 7.1):

  • The background location update mode should NOT be used if you are simply looking for significant changes and region entry / exit events. You will still receive these events, even if the background flag is NOT set, and you will save a lot of battery at the same time.
  • If you do this above, you need to keep in mind the limited allowed background time. If you do not take care of completing network requests, etc. For the allowed time, you will perform network transactions.
  • You should ONLY use the background location mode if you need to use detailed location tracking (e.g. -startUpdatingLocation), in which case this background mode will support your application.
  • Using the background location mode when you do not get a detailed location will not work for your users and may reject your application during the browsing process (depending on how you use the location in your application).
  • Your application can be killed at any time by the OS if you do not have the background location mode set, so you will need to reinitialize the CLLocationManager instance in applicationDidFinishLaunching or applicationWillFinishLaunching to get a subsequent updateLocation or didEnter / ExitRegion. Just because the location wakes up your application with a location update, it does NOT magically create your CLLocationManager without programming it!

Hope this helps!

+2
source

To disable CLLocationManager when the application is in the background, you simply do not need to add the "Application Registers for location updates" to the "Required background modes" file info.plist key.

I suggest using a significant location change service instead of the standard location service, when possible, to conserve the device’s battery.

+1
source

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


All Articles