0

When my application is running in the foreground I see periodic calls to: NSURLSessionTaskDelegate -> URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

When my application moves to the background and is suspended, calls to this method stop so I have no feedback on whether NSURLSessionUploadTask is continuing to upload. Are there any techniques out there for getting some feedback about the upload?

drbobdugan
  • 403
  • 5
  • 12

1 Answers1

2

From looking at other StackOverflow posts about NSURLSessionUploadTask I can see there is a lot of confusion about this feature. Here are some feedback mechanisms I uncovered to help reduce this confusion:

  • use a network proxy and packet sniffer like Wireshark (see this for details). Filter out all traffic except traffic to/from the server you are upload the file to. Look for HTTP Response (200) from the server and a FIN,ACK from the iOS device to signal that the upload is complete and the response has been received. You can also use the packet sniffer to diagnose problems with the upload. Wireshark

  • use Instruments to capture network traffic for the process nsurlsessiond

Instruments capture for nsurlsessiond

  • wait for the upload to complete. If your application is in the background and suspended when the upload completes, then iOS moves your application from the suspended state to actively running in the background and invokes the following methods in this order:
    • via NSURLSessionTaskDelegate -> URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: some calls to this method that were not processed before application went into the background may be called
    • via NSURLSessionTaskDelegate: -> URLSession:dataTask:didReceiveData:
    • via NSURLSessionTaskDelegate -> NSURLSession:task:didCompleteWithError:
    • via NSURLSessionDelegate -> :URLSessionDidFinishEventsForBackgroundURLSession:
    • iOS gives the application 30 seconds TOTAL to handle end of download in the background before suspending the application

I've also put a very basic NSURLSessionUploadTask example application and webserver on github here.

Community
  • 1
  • 1
drbobdugan
  • 403
  • 5
  • 12