Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location updates while app is in the background or suspended

Greetings all.

I am attempting to implement significant location change and region support into my app. While the app is active, there is obviously no problem receiving location updates. My question is how to handle updates when the app is not active.

This is my understanding of what happens if a significant location change or region entry/exit is detected:

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

Is this correct? Am I missing anything?

Thanks for help.

Regards, --John

like image 475
johnnyspo Avatar asked Apr 27 '11 17:04

johnnyspo


1 Answers

You are partly right.

If the app is in background, and you are using significant location change:

  1. The app will call locationManager:locationDidUpdateToLocation:fromLocation
  2. If app crashed while it was in background, it will call application:didFinishLaunchingWithOption: with UIApplicationLaunchOptionLocationKey. You then have to init location manager again to get significant location change. This will then come in to locationManager:locationDidUpdateToLocation:fromLocation. This step is important

If the app is in background, and you are using region monitoring

  1. locationManager:locationDidUpdateToLocation:fromLocation will not be called
  2. the app calls locationManager:didEnterRegion:
like image 137
honcheng Avatar answered Oct 18 '22 03:10

honcheng