开发者

How to get the percentage of file downloaded IOS

开发者 https://www.devze.com 2023-04-06 08:19 出处:网络
Hi Does any one how to calculate the 开发者_Python百科percentage of file downloaded when downloading it from a URL using NSUrl. Please help.

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
0

精彩评论

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