NSURL Loading data percentage Value
I need to read NSURL Loading data percentage value.
That is, I want to read how many percentage amount of data is loading on URL Loading time.
Suppose a URL take 30 seconds to loading data completely, I want to know in 15th sec how many percentage of data is loading in my String, and 20th sec how many percentage of data is loading in my Strin开发者_如何学Cg, like this I need.
First of all, you will have to use NSURLConnection. In its delegate's implementation include the following method:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response {
long long contentLength = [response expectedContentLength];
...
}
Note that the only way to know how many bytes the server is going to return is to retrieve the value from its HTTP response. If you find that expectedContentLength
returns -1 (and you should be prepared for that), the server does not return a meaningful value for the downloaded content size, perhaps because it doesn't support the feature. In such a case you should resort to alternative ways to get the byte size.
精彩评论