I have this app that searches tags on flickr and returns results.
The results are displayed on an infinite collection view.
Results are returned 100 at a time.
I start to scroll and reach the bottom of the scroll view. Another 100 elements are requested from Flickr and the thing works fine.
If I continue to scroll down for a while, after entering the 5th page (elements 400-499), I start to get this error:
NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <D87E6C4C-B8CB-46D1-B891-3E7CDF35ABDF>.<1>"
), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://farm0.static.flickr.com/0/50255650726_a4c7ba2298.jpg, NSErrorFailingURLKey=https://farm0.static.flickr.com/0/50255650726_a4c7ba2298.jpg, _kCFStreamErrorDomainKey=12}
Look at the url.
https://farm0.static.flickr.com/0/50255650726_a4c7ba2298.jpg
if you change farm0
to farm1
the image loads.
I am creating the image download url like this:
func makeDownloadURL() -> URL{
let path = "https://farm\(farm).static.flickr.com/\(server)/\(id)_\(secret).jpg"
return URL(string: path)!
}
The strange part is that if I continue to scroll past the missing images, at some point, valid images start to fill the collection view. Then, the problem again, valid images again, and so one.
I am using this to build the search URL
func makeSearchURLComponents(searchString:String) -> URLComponents? {
var components = URLComponents()
components.scheme = "https"
components.host = "api.flickr.com"
components.path = "/services/rest"
let queryMethod = URLQueryItem(name: "method", value: "flickr.photos.search")
let queryAPI = URLQueryItem(name: "api_key", value: flickrAPI)
let queryFormat = URLQueryItem(name: "format", value: retrieveFormat)
let querySafeSearch = URLQueryItem(name: "safe_search", value: SafeSearch.Safe.rawValue)
let querySearchString = URLQueryItem(name: "tags", value: searchString)
let queryPageNumber = URLQueryItem(name: "page", value: String(pageNumber))
let querycallBack = URLQueryItem(name: "nojsoncallback", value: "1")
components.queryItems = [queryMethod, queryAPI, queryFormat, querySafeSearch, querySearchString, queryPageNumber, querycallBack]
return components
}
why is that.
It appears to be a flickr problem.
The solution is to correct farm to 1 when it is zero.
let correctedFarm = farm == 0 ? 1 : farm
It is a hack to circumvent their bug.