I am using ASIProgressDelegate in one of my view controllers to calculate remaining time for downloading a file. I am calculating average bandwidth by taking the exponential average for which I need to calculate the speed (bytes per second) between every two didReceiveBytes callbacks. I am maintaining a NSTimerInterval between every two didReceiveBytes callbacks and dividing the "bytes" received by this interval(in seconds) to get bytesPerSecond.
bytesPerSecond=(bytes/interval);
Everything works fine but when I switch to another viewController (which takes a couple of seconds to load) the didReceiveBytes callbacks are also paused for that particular amount of time (leading to an increased interval). The problem starts after this point. Depending on for how much time the didReceiveBytes callbacks were paused,a number of didReceiveBytes callbacks are fired one after other within time intervals like 0.00XX seconds. This causes the bytesPerSecond to increase by multiples of 1000 (in my case) leading to incorrect averageSpeed.
Although after few (~ <10 in my case) of these queued up didReceiveBytes callback are fired, normal behaviour is restored with intervals like 0.XX. But the damage is already done as the averageSpeed takes too much time to reflect correct value (mostly not before file download is complete).
Here is debugger output for reference:
LBPS : 70961.2 for 17524 bytes interval:=0.246952 seconds
//-----This is where the switching of viewControllers and hence a pause
//on didReceiveBytes callbacks takes place. Some another http requests
//might be fired to load the destination viewController hence causing the
//pause----//
LBPS : 731.3 for 20220 bytes interval:=27.648044 seconds
LBPS : 30752210.0 for 16176 bytes interval:=0.000526 seconds
LBPS : 22501136.0 for 14828 bytes interval:=0.000659 seconds
LBPS : 7521728.0 for 18872 bytes interval:=0.002509 seconds
//----After several queued up callbacks normal realtime callbacks start//----
LBPS : 64764.6 for 16176 bytes interval:=0.249766 seconds
LBPS : 75252.0 for 18872 bytes interval:=0.250784 seconds
//LBPS:=LastBytesPerSecond
Is this behaviour normal for ASIProgressDelegate? Or am I missing something? Is there anyway I can handle this ambiguity?