开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜