How to get the percentage of file downloaded IOS
Hi Does any one how to calculate the 开发者_Python百科percentage of file downloaded when downloading it from a URL using NSUrl. Please help.
Thanks a Lot Max
you should be able to get the expected content length in your NSURLConnection's delegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
contentLength = [response expectedContentLength];
downloadedContentLength = 0;
...
}
then track the length of the portion you already have in
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
downloadedContentLength += [data length];
int percentage = ((double)downloadedContentLength/contentLength)*100
精彩评论