1

I have been working on an app that allows the downloading of large files. I am using Swift 3 and Alamofire,

The downloads work in the background, and on iOS 10.2.x this all worked perfectly fine. But on updating to iOS 10.3.x when the device is switched to sleep, upon opening the app again the following errors are thrown:

[] nw_socket_get_input_frames recvmsg(fd 6, 1024 bytes): [57] Socket is not connected
[] nw_endpoint_handler_add_write_request [1.1 192.124.249.2:443 failed socket-flow (satisfied)] cannot accept write requests
[] tcp_connection_write_eof_block_invoke Write close callback received error: [22] Invalid argument

The download is continuing in the background, and upon completion will trigger the completion callbacks fine. But because of these errors, it seems the progress callback isn't being called unless I close the app and open it again and reload the table cell view on open.

I can't find much info about these kind of errors online, only information on hiding the errors from being printed to the console.

Can anyone help?

Thanks

Eventured
  • 63
  • 6

1 Answers1

0

I had the same problem trying to download a large file (800 mb aprox) using Alamofire. At first my implementation was calling validate() and then responseData(queue:completionHandler:).

When this error occurs, Alamofire was catching it as a Failure with alamofire.AFError.ResponseValidationFailureReason.dataFileNil (whith no resumeData) which suggest that the closure sent on the to parameter is nil, which wasn't my case.

So my solution was removing the validate() call and doing the validation manually by catching the status codes on a switch.

Now without the validate() call Alamofire was catching the same error as a Failure but with a 200 as status code and resumeData. When this occurs I just make the download again but this time sending the resumeData on the download call. Since the resumeData was almost at 100% (because the error happens when Alamofire is trying to write the file, at the end of the download) the second download was very short.

So basically my code looked like this:

switch response.response?.statusCode {
    // other cases
    case 200:
        if let resumeData = response.resumeData {
           // failed
           // retry the download using resumeData
        } else {
           // succeed finished download
        }
   // more cases
}

If you need more info/details let me know

rgkobashi
  • 2,551
  • 19
  • 25