So in my application I use a NSURLConnection to connect to a server and retrieve text. This is how I initiate my NSURLConnection:
NSMutableURLRequest * serviceRequest = [NSMutableURLRequest requestWithURL:postUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
//Some other code
[serviceRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
[serviceRequest setHTTPMethod:@"POST"];
[serviceRequest setHTTPBody:postData];
//Force to return size
[serviceRequest setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
theConnection = [[NSURLConnection alloc] initWithRequest:serviceRequest delegate:self];
Now it works fine but I am trying to get a progress bar in my application to represent the progress of this request.
Now here are my didReceiveResponse and didReceiveData methods:
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
dlSize = [response expectedContentLength];
NSLog(@"didReceiveResponse: %f", dlSize);
[self.receivedData setLength:0];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
dlProgress = ((float) [data length] / (float) dlSize);
NSLog(@"dlProgress: %f", dlProgress);
}
So this is the issue. As you can see I have two NSLogs in there, but they are not called until the request is done. To be specific I am contacting a server to OCR something and once it is done OCRing and I get the text, that is when these two methods are called. Then the logs return something like this:
2013-07-30 22:50:09.201 app[39381:907] didReceiveResponse: 514.000000
2013-07-30 22:50:09.202 app[39381:907] dlProgress: 1.000000
2013-07-30 22:54:39.651 app[39381:907] didReceiveResponse: 305.000000
2013-07-30 22:54:39.651 app[39381:907] dlProgress: 1.000000
I am not sure why those methods aren't called during the request but maybe somebody on this site knows why? Anyway any tips/comments/suggestions are appreciated so I can get a UIProgressView hooked up with this.
Thanks!