Instance Method

URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:

Periodically informs the delegate of the progress of sending body content to the server.

Declaration

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend;

Parameters

session

The session containing the data task.

task

The data task.

bytesSent

The number of bytes sent since the last time this delegate method was called.

totalBytesSent

The total number of bytes sent so far.

totalBytesExpectedToSend

The expected length of the body data. The URL loading system can determine the length of the upload data in three ways:

  • From the length of the NSData object provided as the upload body.

  • From the length of the file on disk provided as the upload body of an upload task (not a download task).

  • From the Content-Length in the request object, if you explicitly set it.

Otherwise, the value is NSURLSessionTransferSizeUnknown (-1) if you provided a stream or body data object, or zero (0) if you did not.

Discussion

The totalBytesSent and totalBytesExpectedToSend parameters are also available as NSURLSessionTask properties countOfBytesSent and countOfBytesExpectedToSend. Or, since NSURLSessionTask supports NSProgressReporting, you can use the task’s progress property instead, which may be more convenient.

See Also

Working with Upload Tasks

- URLSession:task:needNewBodyStream:

Tells the delegate when a task requires a new request body stream to send to the remote server.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software