I have an issue with the
connection:didWriteData:totalBytesWritten:expectedTotalBytes:
method of the NSURLConnectionDownloadDelegate
under iOS 6.
Under iOS 5 Simulator it works just fine, giving me the right expectedTotalBytes value.
On iOS 6 Simulator, the expectedTotalBytes always returns 0. The totalBytesWritten value is still right.
It's the same request, the same URL, just the OS Version is different.
Has anyone encountered a similar issue or has any idea what could cause this?
Cheers
Kim
Just spent a good amount of time investigating the same issue. It turned out to be that in iOS6 the request is first made with HEAD to investigate the headers, which is not that abnormal.
However it seems headers from the response to the actual GET request are ignored. As a result if your server did not support HEAD or returned 0 content length for HEAD request against a given URL, iOS NSURLConnection will use wrong information.
My problem was that my custom server did not support HEAD requests for files I was downloading, and instead returned a 405 (HTTP Error 405 Method not allowed) which in its own response contained a content length that then iOS6 used when returning expectedTotalBytes, not the correct one from the GET response.
To fix my problem, I first enabled HEAD for my file download requests and then made sure the correct content length was returned. Verified with:
curl -v -I http://url
...
< Content-Length: 23493947
Content-Length: 23493947
Not sure if that is bug in iOS6 or just better compliance with the HTTP standards. Hope that helps others.