Im using NSURLSession
dataTask
with NSOoperationQueue
to download a file with multiple connections for faster speed. Creating operations from NSURLSession
and passing them to OperationQueue
. Now my struggle here is, as i see in apple docs, only downloadTask
has progress tracking, is it even possible to track the bytes received using NSURLSession
dataTask
?
Asked
Active
Viewed 3,520 times
1

Juan Catalan
- 2,299
- 1
- 17
- 23

user2125726
- 127
- 2
- 10
2 Answers
3
per Apple documentation https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionTaskDelegate_protocol/index.html#//apple_ref/occ/intfm/NSURLSessionTaskDelegate/URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend: the delegate is
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didSendBodyData:(int64_t)bytesSent
totalBytesSent:(int64_t)totalBytesSent
totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
URLSession(_:dataTask:didReceiveData:) is not being called, at least not on ios 9.0, otherwise Stefan's answer applies

Anton Tropashko
- 5,486
- 5
- 41
- 66
-
Thank you! helped me a lot. – Asi Givati Nov 07 '16 at 08:24
2
Configure your NSURLSession
to have a delegate that implements the NSURLSessionDataDelegate
protocol.
In the delegate, implement the URLSession(_:dataTask:didReceiveData:)
method, wich will be called when data comes in. Which is a good place to update for example a progress bar.

Stefan Arentz
- 34,311
- 8
- 67
- 88
-
Thanks @StefanArentz, could you please explain more in depth on how do i have to create the delegate ? I know how to configure the NSURLSession to use a delegate, but im not sure how to create the delegate itself. thanks – user2125726 May 28 '15 at 15:31