I'm trying to refresh the progress bar in an UIProgressView for an upload request with NSURLConnection
. The goal is to refresh the progress bar while uploading a picture. After several searches, I managed to use the didSendBodyData
of my connection delegate to check the progress like this :
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
if([self.delegate respondsToSelector:@selector(progressView)])
{
self.delegate.progressView.progress = (totalBytesWritten / totalBytesExpectedToWrite) * 100.0;
}
}
Everything works fine, but the problem is that this method is only called one time... So the bar stay at 0% for a moment, then go instantly to 100% without intermediate. I tried (with iOS6 develloper tool on iPhone) to set my connection to a slow edge connection to figure if it is just my upload that is too fast, but no, the upload take a while at 0, then go to 100% instantly and the method is called only one time...
Any idea please ? Thank you ! I can't figure how to fix that...