I have a JSON request that gets sent to a server based on the response of another JSON request, I used this method to check what NSURL connection is being used to handle the response:
if(connection == connection1) {
// Connection 1
} else if(connection == connection2) {
// Connection 2
}
It works for the first connection, which is sent out like this:
NSString *jsonStr = [NSString stringWithFormat:@"https://api.flightstats.com/flex/flightstatus/rest/v2/json/flight/status/%@/%@/dep/%@?appId=%@&appKey=%@&utc=false",airline.text,flightnumber.text,datestring,flightAPIIDstring,flightAPIkeystring];
NSURL *jsonurl = [NSURL URLWithString:jsonStr];
flightTrackJSONconnectionrequest = [NSURLRequest requestWithURL:jsonurl];
flighttrackJSONconnection =[[NSURLConnection alloc]
initWithRequest:flightTrackJSONconnectionrequest delegate:self];
if(flighttrackJSONconnection){
jsonresponse = [[NSMutableData alloc] init];
} else {
}
However, on the connectionDidFinishLoading for my first connection (flighttrackJSONconnection), when I use this code, the request for the 2nd connection is not sent out at all:
NSString *departjsonStr = [NSString stringWithFormat:@"https://api.flightstats.com/flex/airports/rest/v1/json/iata/%@?appId=%@&appKey=%@",DepartACode,flightAPIIDstring,flightAPIkeystring];
NSURL *departjsonurl = [NSURL URLWithString:departjsonStr];
departairportcheckJSONconnection = [NSURLRequest requestWithURL:departjsonurl];
departairportcheckJSONconnection =[[NSURLConnection alloc]
initWithRequest:departairportcheckJSONconnectionrequest delegate:self];
if(departairportcheckJSONconnection){
departairportlookup = [[NSMutableData alloc] init];
} else {
}
I added NSLog checks to the connection didFailWithError, connection didReceiveResponse and connectionDidReciveData all to find that the only NSURL request going out was my flighttrackJSONconnection request...
So I'm wondering, did I miss something in my code, or is it simply not possible to send another NSURLRequest when it calls connectionDidFinishLoading?
Sorry if I seem like a noob, I'm just confused a bit...
Also, all the JSON parsing code (at least for the flighttrackJSONresponse connection) and such works fine on connectionDidFinishLoading, so its not like I made a mistake declaring anything & if it makes any difference, I'm trying to send 2 requests on the connectionDidFinishLoading, each of them with their own NSURLConnection and NSURLRequest names declared on the .h, I have the same issue with both.
Thanks for any tips or ideas guys..