consider this piece of code:
func load(url: URL?, callback: ((UIImage?) -> Void)? = nil) -> UIImage? {
guard let url = url else {
return nil
}
if let image = cache[url] {
return image
}
guard let callback = callback else {
return nil
}
var request = URLRequest(url: url)
request.httpMethod = "GET"
let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 10
let session = URLSession(configuration: config, delegate: nil, delegateQueue: OperationQueue.main)
let task = session.dataTask(with: request) { data, response, error in
guard let data = data else {
return
}
DispatchQueue.global().async {
let image = UIImage(data: data)
DispatchQueue.main.async {
self.cache[url] = image
callback(image)
}
}
}
task.resume()
return nil
}
We have run into an issue where in session.dataTask
the data
is returned as nil and the error is some sort of undecipherable NSURLError. Debugging into it does not give any useful leads to me as to what the problem might be. We have been able to determine that some URLs work and some don't but it is not clear where the problem lies.
The url in question is this:
http://website.com////assets//P//wa//_resampled//paddedimage400400-apicture.gif
This is what I get from copying the error, this reinforces again that something is wrong with the url:
error Error? (instance_type = 0x0000608000246930 -> 0x0000000106a2ff48 (void *)0x0000000106a2ff20: NSURLError) some
A url that works is this one:
https://api.website.com/assets/P/wa/_resampled/picture.jpg
I mean obviously there are differences between both URLs but I can assure you that both work in the browser and correctly display an image.
Does anybody know how to decipher the NSURLError or get it into some readable format?
If not, does anybody have a specification for the formats that NSURL can work with and that we might be violating?