I had the same question now in 2023 😅 and I still couldn't find any good response using Apple Docs or Google. I also tried to ask it for ChatGPT and the answer was
The lastLocation variable in your code reflects the last known
location that your app has received through the CLLocationManager
object. This means that it represents the location that your app has
acquired, rather than a system-level location that other apps or the
iOS might have queried for.
But I also wanted to make a test using the iOS simulator. I made two apps with different bundle ids.
App A has two buttons each of them with the following functionalities:
- First button: Ask for a location using
locationManager.requestLocation()
and print the result in func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]
- Second button: Print the last location using
locationManager.location
App B has only one button with the following functionality:
- Ask for a location using
locationManager.requestLocation()
and print the result in func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]
After that, I followed these steps:
- Run App A in the iOS simulator
- Set simulated location (Features > Location > Custom location) to eg. (-10, -20)
- Request a fresh location (First button). The app gives me the following:
new location: [<-10.00000000,-20.00000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 18/04/2023 10:45:53 Horário Padrão de Brasília]
- Request the last location (Second button). The app gives me the following:
last location: Optional(<-10.00000000,-20.00000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 18/04/2023 10:45:53 Horário Padrão de Brasília)
Run App B in the same iOS simulator
Set simulated location (Features > Location > Custom location) to eg. (30, 40)
Request a fresh location. The app gives me the following:
[<+30.00000000,+40.00000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 18/04/2023 10:48:44 Horário Padrão de Brasília]
Run app A again
Request the last location again (Second button). The app gives me the following:
last location: Optional(<+30.00000000,+40.00000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 18/04/2023 10:48:44 Horário Padrão de Brasília)
- Change the simulated location (Features > Location > Custom location) to eg. (5, 5). The app gives me the following:
last location: Optional(<+30.00000000,+40.00000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 18/04/2023 10:48:44 Horário Padrão de Brasília)
So, if the device follows the simulators, locationManager.location
should give us a global iOS system level last location.