Ash
Ash

Reputation: 2294

NSUrlConnection didFailWithError -1005

I had a look at this thread and a few others but they don't address my problem:

Why NSURLConnection failed with Error Domain=NSURLErrorDomain Code=-1005 “The network connection was lost.”

I seem to only get the following error debugging my app (through Xcode) on a physical iPad:

enter image description here

The files that I'm trying to download are typically around 400MB in size and hosted on a CDN. Sometimes the downloads go through without any issues and other times they fail at some point during the download.

It seems to always work on a simulator.

iOS development version: 8.4

iOS deployment version: 8.0

Upvotes: 0

Views: 325

Answers (1)

dgatwood
dgatwood

Reputation: 10407

Networks just glitch sometimes.

I would strongly recommend using NSURLSession and download tasks. That way, you can trivially resume the transfer when the network goes away and comes back. When a connection fails, use reachability to determine when to try again, then tell the download task to resume.

With that said, if you need to support iOS 6 and earlier, you can also do byte range requests with NSURLConnection; it just requires a bit more work to do it that way, because you have to save the partial data, explicitly specify the starting position in the byte range request header, and then glue the pieces together yourself. If you need more details on that approach, let me know in the comments, and I'll try to provide them.

Upvotes: 1

Related Questions