开发者

calculating total time of downloading data?

开发者 https://www.devze.com 2022-12-24 01:34 出处:网络
i am using apple\'s sample URLCache,but when i mention url, it loads data perfectly but i w开发者_高级运维ant to calculate time of downloading(till completion),is there anyh built in method?Add NSDate

i am using apple's sample URLCache,but when i mention url, it loads data perfectly but i w开发者_高级运维ant to calculate time of downloading(till completion),is there anyh built in method?


Add NSDate property to your class, name it,let's say, downloadStart and when download starts, save actual time to it - self.downloadStart = [NSDate date];

Then in -connectionDidFinishLoading: delegate method implementation do:

NSDate *downloadEnd = [NSDate date];
NSTimeInterval totalTime = ([downloadEnd timeIntervalSince1970] - [downloadStart timeIntervalSince1970]);

//Total time now contains number of seconds since download start time
NSLog(@"Download finished in %f seconds", totalTime);

self.downloadStart = nil;

That's it. Please note that the code above is just a kind of abstract how to do the trick, so don't use in copy & paste manner.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号