I am making multiple calls to server, I am using for loop for it
for(int i = 0; i <count; i++)
{
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:finalJson options:NSJSONWritingPrettyPrinted error:&error];
if (!jsonData) {
NSLog(@"Error creating JSON object: %@", [error localizedDescription]);
}
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"httpLink"]];
[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:APIKEY forHTTPHeaderField:@"X_API_KEY"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonData];
m_dataPush = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
[m_dataPush start];
}
For example suppose the count is 3, then the "m_dataPush" is called thrice
So now I have the delegate methods to handle the response.
But in my "connectiondidfinishLoading" function is called only once, and I am only getting one response.But in fact I should have got three responses.
Here are my delegate functions
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if(connection == m_dataPush || connection == m_dataPull)
{
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
m_responseCode = [httpResponse statusCode];//Get status code for response
m_ResponseData = [[NSMutableData alloc] init];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to the instance variable you declared
if(connection == m_dataPush || connection == m_dataPull)
{
[m_ResponseData appendData:data];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// The request is complete and data has been received
// You can parse the stuff in your instance variable now
if(connection == m_dataPush || connection == m_dataPull )
{
NSDictionary *response = [NSJSONSerialization JSONObjectWithData: m_ResponseData options: 0 error: &e]; //I am using sbjson to parse
}
}
So please help me out, in how to manage this
Regards