@@ -26,7 +26,7 @@ open class URLSessionAdapter: NSObject, SessionAdapter, URLSessionDelegate, URLS
26
26
}
27
27
28
28
/// Creates `URLSessionDataTask` instance using `dataTaskWithRequest(_:completionHandler:)`.
29
- open func createTask( with URLRequest: URLRequest , progressHandler: @escaping ( Int64 , Int64 , Int64 ) -> Void , completionHandler: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) -> SessionTask {
29
+ open func createTask( with URLRequest: URLRequest , progressHandler: @escaping ( Progress ) -> Void , completionHandler: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) -> SessionTask {
30
30
let task = urlSession. dataTask ( with: URLRequest)
31
31
32
32
setBuffer ( NSMutableData ( ) , forTask: task)
@@ -60,13 +60,14 @@ open class URLSessionAdapter: NSObject, SessionAdapter, URLSessionDelegate, URLS
60
60
return objc_getAssociatedObject ( task, & taskAssociatedObjectCompletionHandlerKey) as? ( Data ? , URLResponse ? , Error ? ) -> Void
61
61
}
62
62
63
- private func setProgressHandler( _ progressHandler: @escaping ( Int64 , Int64 , Int64 ) -> Void , forTask task: URLSessionTask ) {
63
+ private func setProgressHandler( _ progressHandler: @escaping ( Progress ) -> Void , forTask task: URLSessionTask ) {
64
64
objc_setAssociatedObject ( task, & taskAssociatedObjectProgressHandlerKey, progressHandler as Any , . OBJC_ASSOCIATION_RETAIN_NONATOMIC)
65
65
}
66
66
67
- private func progressHandler( for task: URLSessionTask ) -> ( ( Int64 , Int64 , Int64 ) -> Void ) ? {
68
- return objc_getAssociatedObject ( task, & taskAssociatedObjectProgressHandlerKey) as? ( Int64 , Int64 , Int64 ) -> Void
67
+ private func progressHandler( for task: URLSessionTask ) -> ( ( Progress ) -> Void ) ? {
68
+ return objc_getAssociatedObject ( task, & taskAssociatedObjectProgressHandlerKey) as? ( Progress ) -> Void
69
69
}
70
+
70
71
// MARK: URLSessionTaskDelegate
71
72
open func urlSession( _ session: URLSession , task: URLSessionTask , didCompleteWithError error: Error ? ) {
72
73
handler ( for: task) ? ( buffer ( for: task) as Data ? , task. response, error)
@@ -79,6 +80,8 @@ open class URLSessionAdapter: NSObject, SessionAdapter, URLSessionDelegate, URLS
79
80
80
81
// MARK: URLSessionDataDelegate
81
82
open func urlSession( _ session: URLSession , task: URLSessionTask , didSendBodyData bytesSent: Int64 , totalBytesSent: Int64 , totalBytesExpectedToSend: Int64 ) {
82
- progressHandler ( for: task) ? ( bytesSent, totalBytesSent, totalBytesExpectedToSend)
83
+ let progress = Progress ( totalUnitCount: totalBytesExpectedToSend)
84
+ progress. completedUnitCount = totalBytesSent
85
+ progressHandler ( for: task) ? ( progress)
83
86
}
84
87
}
0 commit comments