I'm using NSURLSession et al to download files in my iPhone app. It works correctly except for large (>20MB) files. Then, without exception, the
NSURLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:
callback returns -1 for totalBytesExpectedToWrite.
Embedded in the NSURLSessionDownloadTask.response object there is an HTTP header dictionary with this key/value pair:
"Content-Length" = (
22268238
);
This is the correct value that I need so I can monitor the download progress, not the "expected value".
How can I obtain this header value from the NSURLResponse object? If I access response.expectedContentLength it always returns -1.
One would expect a -allHeaderFields method, or perhaps
[response headerValueForKey:@"Content-Length"] or some such.
Is there a way to obtain the NSURLResponse object's HTTP header values in a NSDictionary?