Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send multiple url request from a NSURLConnection delegate?

This is the logical flow for my application:

  1. At first, when the view controller has finished loading, then a NSURLConnection request can start its execution

  2. The response consists in xml data

  3. After parsing that xml I need to send another NSURLConnection request.

  4. After sending the second request, if the response is ok, I receive other xml data

  5. After parsing the second xml, I have to check some issues between first and second xml data.

So, is it possible to send multiple request? How? I do not need code, you could just explain it.

Thank you in advance.

like image 207
Yamen Emon Avatar asked Dec 07 '22 16:12

Yamen Emon


2 Answers

I do this with the NSURLConnection Making them properties, then checking which one it is:

 @property (nonatomic,retain) NSURLConnection *myConnection;
@property (nonatomic,retain) NSURLConnection *mySecondConnection;

then in the delegate:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

     if (connection == myConnection){
       //do something
    }

    if (connection == mySecondConnection){
       // do something else
        }

}

You can pass your NSURLRequest to the connection:

self.myConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
like image 184
Hubert Kunnemeyer Avatar answered Feb 08 '23 22:02

Hubert Kunnemeyer


There is a third party library available which is a wrapper on CFNetwork is ASIHTTPREQUEST

This Library should do work for you. so that you don't have to write the code from scratch. other alternative is create one class which will be responsible for creating NSURLConnection then sending the request and finally notify to view controller using delegate or notification one data is received .

like image 31
iOSPawan Avatar answered Feb 09 '23 00:02

iOSPawan