As a test, we have used dummy coordinates, but we have a powerful GPS on board, and it's time to use it.
To use the Core Location framework service, we need to instruct iOS that our app is using it.
To do this, we must add the NSLocationAlwaysUsageDescription
key with a string; for example, this application requires location services to get the weather of your current location in Info.plist
.
Then, we add a new property to PrettyWeatherViewController
:
private var locationDatastore: LocationDatastore?
Next, we change the viewWillAppear
function:
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) locationDatastore = LocationDatastore() { [weak self] location in FlickrDatastore().retrieveImageAtLat(location.lat, lon: location.lon){ image in self?.render(image) } } }
Our simple wrapper around LocationManager
basically calls the provided closure when the location changes. The implementation is...