I am trying to show the progress of a download from an API, but NSURLConnectionDelegate does not have a total bytes value anywhere. Is there some way to get the total amount of bytes that I am downloading before it finishes the download?
Asked
Active
Viewed 2,267 times
1 Answers
8
You can get expected contents length from NSURLResponse via -expectedContentLength
method. For example if you use NSURLConnection
and NSURLConnectionDelegate
you can obtain that information in delegate's connection:didReceiveResponse:
method:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
...
long long contentLength = [response expectedContentLength];
...
}

Vladimir
- 170,431
- 36
- 387
- 313
-
Thats great! Does NSURLResponseUnknownLength come up very often? But hopefully this works out! – RileyE Sep 14 '12 at 18:10
-
@RileyE sorry, don't know about NSURLResponseUnknownLength... But since I never seen that might mean that it is rather rare :) – Vladimir Sep 14 '12 at 18:40