Question

I'm working on a download manager and I'm trying to update labels indicating the download speed and the percentage left.

It updates way too fast within connection:didReceiveData though, and using a performSelector and delaying it from that method doesn't work (it just delays it for that long before starting).

What should I do to update something like download speed or percentage left?

Was it helpful?

Solution

If you don't want to update the display as quickly as possible, just keep note of the time when you last updated it. If the current time is not at least, say, 0.5 seconds since the last update, just don't update on this pass.

OTHER TIPS

It would be helpful to see how you calculate speed and percentage but one approach will be :

  1. Calculate time elapsed (in seconds) between two calls of connection:didReceiveData
  2. Take the size of the current received data (let's call it size)
  3. Sum total data size downloaded so far (lets call it downloadedSize)
  4. Speed = size / timeElapsed
  5. Percentage = downloadedSize / Total data size (Assuming you have it)
  6. Convert to desired units
  7. Update the labels (I do not see why you should delay here)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top