I have the following code:
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://some-example-domain.com/api"]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:30.0];
[NSURLConnection sendAsynchronousRequest:theRequest
queue: [NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (!error && data) {
// success!! - no errors and data returned
NSLog(@"success");
} else {
// error!! - something whent wrong
NSLog(@"failure: %@", [error localizedDescription]);
}
}
];
which works well - except for odd occasions when the server only sends part of the desired response (eg. half of a JSON response from an API) (it still is 'successful' according to my 'if' statement)
Is there some way using this block based method that I can check to see that the data received is complete??
I have tried looking into the NSURLResponse *response - but can't quite figure out how to use it (or, if it is indeed useful in this scenario). Any ideas on how to test for 'partially received' data returned by the block?