Location updates when the app is in the background or paused

Welcome all.

I am trying to implement significant location changes and region support in my application. Although the application is active, obviously there is no problem getting location updates. My question is how to handle updates when the application is inactive.

This is my understanding of what happens if a significant change in location or recording / leaving the region is detected:

  • If the application is in the background or suspended, iOS calls locationManager: didUpdateToLocation: fromLocation: (or locationManager: didEnterRegion :) for my existing location delegate.
  • If the application is completed, iOS calls the application: didFinishLaunchingWithOptions: with the key UIApplicationLaunchOptionsLocationKey in my application. At this point, I need to create a new instance of the location manager in order to get the new location.

It is right? Did I miss something?

Thanks for the help.

Regards, --John

+7
source share
3 answers

You are partly right.

If the application is in the background and you are using a significant change in location:

  • The application will call locationManager: locationDidUpdateToLocation: fromLocation
  • If the application crashed when it was in the background, it calls the application: didFinishLaunchingWithOption: using UIApplicationLaunchOptionLocationKey. Then you need to start the location manager again in order to achieve a significant change in location. Then it will go into locationManager: locationDidUpdateToLocation: fromLocation. This step is important.

If the application is in the background and you are using area monitoring

  • locationManager: locationDidUpdateToLocation: fromLocation will not be called
  • application calls locationManager: didEnterRegion:
+7
source

To get a location update when the application is in the background and when the application is paused, these are 2 very different scenarios. You will have to treat them differently.

You can use the UIApplicationLaunchOptionsLocationKey key, if your locationManager uses the startMonitoringSignificantLocationChanges method, you cannot use startUpdatingLocation .

To get location updates when

A) The application is in the background, see Help services that do not work in iOS 7

B) The application is paused / completed, see How to get location updates for iOS 7 and 8 Even when the application is paused

I wrote 2 a very long article explaining the difference between scenario 2. The source code for the above scenario is also available on GitHub.

+3
source

I believe that it always calls the application: didFinishLaunchingWithOptions if your application is not in the foreground.

-3
source

All Articles