Reputation: 748
I am trying to figure out how to handle changes to location permissions correctly. So far, I handle changes with delegate method: locationManager:didChangeAuthorizationStatus:
. But I am only certain this works while the app is running in the foreground.
What happens if the user changes location permission in the Settings app. If the app is not running, then the app will see the changes when the app starts up, so that's fine. However, if the app is suspended, how does the app get notified? Does the delegate method locationManager:didChangeAuthorizationStatus:
still get called at one point?
Upvotes: 2
Views: 1684
Reputation: 2881
The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.
So there is a bit of a nuance in your question. While the app is specifically in the suspended state, it does not run any code. However, when the location state changes (assuming your app has called requestAlwaysAuthorization and the user has granted access), the app will be "woken up" and placed back into the background state. From the iOS Developer Library
If you leave the significant-change location service running and your iOS app is subsequently suspended or terminated, the service automatically wakes up your app when new location data arrives. At wake-up time, the app is put into the background and you are given a small amount of time (around 10 seconds) to manually restart location services and process the location data. (You must manually restart location services in the background before any pending location updates can be delivered.
So to answer your question, the app does not receive location updates in the suspended state; however, it is placed into the background state where it eventually does receive the location update.
Upvotes: 1