I have a standard asynchronous NSURLConnection operation and NSMutableData that loads json from a web service.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
_responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSDictionary *response = [NSJSONSerialization JSONObjectWithData:_responseData
options:NSJSONReadingAllowFragments
error:&error];
_responseJson = response;
}
Most of the time it works flawlessly, but for json payloads over an undetermined size I get Cocoa Error 3840 (I have verified the validity of the json). Interestingly when I NSLog the raw data in
-connectionDidFinishLoading:
It doesn't log all at once and while the logic in the method continues to execute, the raw data continues to load in the console in a staggered fashion.
-stringFromData:encoding:
Also returns nil while the console logs staggered output. The actual payload is only ~.25mb. I have tried [[NSMutableData alloc] initWithCapacity:] with the same result.