I try to load an image with newest version of XCode and AppleTV but suddenly the payload is always nil while the status code of the response is 200. I also recognised SSL errors in my console. The download fails with images that are availabe in my browser. E.g. https://www.w3schools.com/w3css/img_lights.jpg
private func fetchImage(url: URL) {
dispatchGroup.enter()
URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data, error == nil else {
self.dispatchGroup.leave()
return
}
logger.error("Download failed \(response?.suggestedFilename ?? url.lastPathComponent)")
//simplified here
let image = UIImage(data: data)
self.dispatchGroup.leave()
}.resume()
}
Any idea what might cause this?
Your code seems okay to me (Tested). The SSL error is happening because you need to set up App security in your Plist file.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>