提交 a285dd54 编写于 作者: C Christian Noon

Data task progress closures are now always called.

Data tasks with a registered progress closure will now always call that closure when data is received as well as update the NSProgress object stored in the `TaskDelegate`. The `Request.progress(_:)` method documentation was also updated to reflect the behavior of data tasks.

This addresses the issues reported in #407.
上级 7d644e07
......@@ -647,7 +647,7 @@ public class Request {
Sets a closure to be called periodically during the lifecycle of the request as data is written to or read from the server.
- For uploads, the progress closure returns the bytes written, total bytes written, and total bytes expected to write.
- For downloads, the progress closure returns the bytes read, total bytes read, and total bytes expected to write.
- For downloads and data tasks, the progress closure returns the bytes read, total bytes read, and total bytes expected to read.
:param: closure The code to be executed periodically during the lifecycle of the request.
......@@ -871,9 +871,13 @@ public class Request {
mutableData.appendData(data)
if let expectedContentLength = dataTask.response?.expectedContentLength {
dataProgress?(bytesReceived: Int64(data.length), totalBytesReceived: Int64(mutableData.length), totalBytesExpectedToReceive: expectedContentLength)
}
let totalBytesReceived = Int64(mutableData.length)
let totalBytesExpectedToReceive = dataTask.response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown
progress.totalUnitCount = totalBytesExpectedToReceive
progress.completedUnitCount = totalBytesReceived
dataProgress?(bytesReceived: Int64(data.length), totalBytesReceived: totalBytesReceived, totalBytesExpectedToReceive: totalBytesExpectedToReceive)
}
func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, willCacheResponse proposedResponse: NSCachedURLResponse, completionHandler: ((NSCachedURLResponse!) -> Void)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册