I am using NSURLConnection to download a zipped file from a web service. In the didReceiveData I append the data to a file and using a good internet connection all appears to work correctly. The file is transparently unzipped as it is downloaded. If, however, I have a poor internet connection the connectionDidFinishLoading appears to be called before all the data has been received. Is there another delegate method that I should be trapping or some kind of timeout in NSURLConnection that is making it think that the download is finished as opposed to calling didFailWithError?
views:
35answers:
1
+1
A:
you should check that the size of the received data is as expected.
the following will get you the expected size of data:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
long long dataSize = [response expectedContentLength];
}
every time you get a call to didReceiveData, reduce it from the dataSize, and if you get a call to connectionDidFinishLoading and the dataSize is bigger than 0, there is a problem.
Guy Ephraim
2010-08-24 14:23:54
Thanks that will resolve my issue but I still don't understand why NSURLConnection thinks it has finished without error when there is clearly something wrong.
Russ
2010-08-27 18:13:45
Web servers doesn't obligated to report an error on timeout, because in some cases the data you already got might be enough, and if not try again or resume from the place you stopped
Guy Ephraim
2010-08-27 23:23:44