user2000452
user2000452

Reputation:

How to find remaining time for uploading

In my Iphone app,I am uploading video to the server. I can Find out the total bites and uploading bites.Is there any way to find the remaining time for upload process finish

I am printing bites like this ------bytes uploaded------total bytes-----------

2013-02-07 01:25:33.439 VideoProject[9170:907] ------32768------2195238-----------
2013-02-07 01:25:33.451 VideoProject[9170:907] ------65536------2195238-----------
2013-02-07 01:25:33.456 VideoProject[9170:907] ------98304------2195238-----------
2013-02-07 01:25:33.462 VideoProject[9170:907] ------131072------2195238-----------
.
.
.
.
2013-02-07 01:25:54.443 VideoProject[9170:907] ------2129920------2195238-----------
2013-02-07 01:25:54.449 VideoProject[9170:907] ------2145728------2195238----------- 
2013-02-07 01:25:55.215 VideoProject[9170:907] ------2162688------2195238----------- 
2013-02-07 01:25:55.222 VideoProject[9170:907] ------2193380------2195238-----------
2013-02-07 01:25:55.542 VideoProject[9170:907] ------2195238------2195238-----------

Upvotes: 0

Views: 257

Answers (3)

Justin Mathews
Justin Mathews

Reputation: 512

  • get time for bytes uploaded in seconds.
  • estimate total time in seconds. This can be found by comparing the bytes
  • find remaining time by finding the difference.
  • use the below to get as hour ,min,sec.

`

- (NSDictionary*)createTimemapForSeconds:(int)seco                                   
  {
       int hours = floor(seco / (60 * 60) );

       float minute_divisor = seco % (60 * 60);
       int minut = floor(minute_divisor / 60);

       float seconds_divisor = seco % 60;
       seco = ceil(seconds_divisor);

       NSDictionary * timeMap = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSNumber numberWithInt:hours], [NSNumber numberWithInt:minut], [NSNumber numberWithInt:seco], nil] forKeys:[NSArray arrayWithObjects:@"h", @"m", @"s", nil]];

       return timeMap;
    }

Upvotes: 1

Vishnu Dany
Vishnu Dany

Reputation: 31

Using Reachability you can achieve this click here

Using reachability u can calculate the speed of network and then with that speed you can divide remaining bytes and can produce the result of how time remaining for upload,etc..

Hope this helps..

Upvotes: 1

Cyrille
Cyrille

Reputation: 25144

You can save the start date, and on every call of your progress function (or block), compute the elapsed time since start, and find the estimated remaining time amount with a simple cross multiplication, as you know how many bytes there's left :

elapsed_time * total_bytes = total_time * downloaded_bytes
remaining_time = total_time - elapsed_time

But yes, network condition might change anytime, so that's not really accurate.

Upvotes: 1

Related Questions