@@ -26,7 +26,7 @@ open class URLSessionAdapter: NSObject, SessionAdapter, URLSessionDelegate, URLS
2626 }
2727
2828 /// 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 {
3030 let task = urlSession. dataTask ( with: URLRequest)
3131
3232 setBuffer ( NSMutableData ( ) , forTask: task)
@@ -60,13 +60,14 @@ open class URLSessionAdapter: NSObject, SessionAdapter, URLSessionDelegate, URLS
6060 return objc_getAssociatedObject ( task, & taskAssociatedObjectCompletionHandlerKey) as? ( Data ? , URLResponse ? , Error ? ) -> Void
6161 }
6262
63- private func setProgressHandler( _ progressHandler: @escaping ( Int64 , Int64 , Int64 ) -> Void , forTask task: URLSessionTask ) {
63+ private func setProgressHandler( _ progressHandler: @escaping ( Progress ) -> Void , forTask task: URLSessionTask ) {
6464 objc_setAssociatedObject ( task, & taskAssociatedObjectProgressHandlerKey, progressHandler as Any , . OBJC_ASSOCIATION_RETAIN_NONATOMIC)
6565 }
6666
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
6969 }
70+
7071 // MARK: URLSessionTaskDelegate
7172 open func urlSession( _ session: URLSession , task: URLSessionTask , didCompleteWithError error: Error ? ) {
7273 handler ( for: task) ? ( buffer ( for: task) as Data ? , task. response, error)
@@ -79,6 +80,8 @@ open class URLSessionAdapter: NSObject, SessionAdapter, URLSessionDelegate, URLS
7980
8081 // MARK: URLSessionDataDelegate
8182 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)
8386 }
8487}
0 commit comments