0

How to measure a downloadTask Speed:

The Method which I thought is:

calc the last 3s avg speed, and reset received Bytes after 3s, and start a NSTimer which every 0.8s call once.

But this will cause a problem: After 3s the NSTimer call at once, the received Bytes has been reset to 0, but I want a Smooth speed.

Dejauu
  • 109
  • 2
  • 10

1 Answers1

0

First, use NSURLSessionDelegate. If you are using completionHandler: delegate methods won't be called. Then in:

-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data

you can add your own counter of [data length]. Collect and reset it in a synchronized way using NSTimer and you have it. Remember that NSTimer is not firing exactly as specified so if you need better precision store exact times of measurements

gheni4
  • 273
  • 3
  • 16