Alamofire ImageDownloader request cancelled with error code -999

597 Views Asked by At

Edit: See solution in comments.

I am attempting to download user profile avatars from our server, and am experiencing an issue, where regardless of the URL, Alamofire ImageDownloader requests fail with a "cancelled" status and an error code -999. I've tried downloading from other domains that have nothing to do with our app, and see the same problem every time. All of the URLs I've tried so far are https, as our app's info.plist blocks non-secure URLs. However, I've verified that the images being requested can be downloaded in an unauthenticated web browser without any issue. Also, we're using Alamofire SessionManager successfully all over the app, including with requests that require authentication, so this phenomenon seems to be limited to ImageDownloader.

Sample code:

 let downloader = ImageDownloader(configuration: ImageDownloader.defaultURLSessionConfiguration(),
                    downloadPrioritization: .fifo,
                    maximumActiveDownloads: 4,
                    imageCache: AutoPurgingImageCache())
let testString = "https://www.some-domain.com/image-url.jpg"
let urlRequest = URLRequest(url: URL(string: testString)!)

downloader.download(urlRequest) { response in
  debugPrint(response.result)
  if let image = response.result.value {
    print(image)
    self.profilePicture = response.result.value
  } else {
  self.profilePicture = UIImage(named: "avatar")
}

The resulting error looks like this:

2018-11-27 15:32:06.457067-0800 Tocca Dev[945:145021] Task <88DB86C7-7C28-44EB-8ABA-54008A3CC97C>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://www.some-domain.com/image-url.jpg, NSErrorFailingURLKey=https://www.some-domain.com/image-url.jpg, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <88DB86C7-7C28-44EB-8ABA-54008A3CC97C>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <88DB86C7-7C28-44EB-8ABA-54008A3CC97C>.<1>, NSLocalizedDescription=cancelled} [-999]
2018-11-27 15:32:06.476488-0800 Tocca Dev[945:145023] Task <88DB86C7-7C28-44EB-8ABA-54008A3CC97C>.<1> HTTP load failed (error code: -999 [1:89])
2018-11-27 15:32:06.477430-0800 Tocca Dev[945:145023] Task <88DB86C7-7C28-44EB-8ABA-54008A3CC97C>.<1> finished with error - code: -999

Any help would be appreciated.

0

There are 0 best solutions below