Before moving on to downloading the actual forecast, we'll introduce the topic of networking downloading a geo-localized background image.
To get an image, we'll use the API of Flickr, a famous image-hosting website, using a convenient Pod. First of all, we override the viewWillAppear
function in PrettyWeatherApp
so that a new image will be downloaded every time View Controller appears:
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) let lat:Double = 48.8567 let lon:Double = 2.3508 FlickrDatastore().retrieveImageAtLat(lat, lon: lon){ image in self.render(image) } }
To implement the searching feature, we set a dummy value using the coordinates of Paris. Then, we create a new file named FlickrDatastore
:
import FlickrKit class FlickrDatastore { private let OBJECTIVE_FLICKR_API_KEY = "CREATE_API_KEY" private let OBJECTIVE_FLICKR_API_SHARED_SECRET = "CREATE_SHARED_SECRET" ...