Multiple Asynchronous URL Requests

My iPhone app was “lagging” or rather “frozen” when it passed after the screen started. I think this is due to registration for remote push notifications sent as a synchronous request, and therefore I would like to change this to asynchronous. This is a problem, since I am already sending one asynchronous request to receive some data and save it on the phone. So, I would like to send both of these requests asynchronously and make them do two different things in - (void)connectionDidFinishLoading:(NSURLConnection *)connection. So I need to know which of the two completed connections.

Is there any way to do this? Will there be any way to distinguish by the URL of the finished connection? In fact, I thought it would be as easy as installing tagand checking this in - (void)connectionDidFinishLoading:(NSURLConnection *)connection, but this is not possible.

Does anyone know how I can do this?

0
source share
3 answers

As Calle said, best of all is a class that processes the connection, parses the response, and returns data in a pretty delegate function.

, - 2 NSURLConnections , ivars. - NSURLConnection * pushNotificationConnection; NSURLConnection * someOtherConnection;

didReceiveData :

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    if (connection == pushNotificationConnection)
    {
        // handle the push notification related data
    }
    else if (connection == someOtherConnection)
    {
        // handle the other connection
    }
}
+2

- . , , , , ( ) .

, , . PushNotificationRequestor SomeLoader. HTTP- ( ), connectionDidFinishLoading: ..

0
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  if ([connection isEquals:pushNotificationConnection]) {
    // handle the push notification related data
  } else if ([connection isEquals:someOtherConnection]) {
    // handle the other connection
  }
}
0
source

All Articles