I am trying to download a JSON with NSURLConnection, but unless I force the app to pause some seconds the data I get isn't complete. It is always around 2600 bytes and my response should be around 70000.
Any clue why is this happening?
Thank You
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
_responseData = [[NSMutableData alloc] init];
//sleep(10);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_responseData appendData:data];
[self getDataJSON: _responseData];
}
didReceiveData is called a lot of times, while it is receiving data
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_responseData appendData:data];
}
You have to wait until it finish receiving data
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
[self getDataJSON: _responseData];
}
You can get complete data when connection is finished. NSURLConnection finishes when it's connectionDidFinishLoading: delegate method is called. Try [self getDataJSON: _responseData]; in that method. Good Luck!
来源:https://stackoverflow.com/questions/20095234/didreceivedata-is-not-getting-all-data