My iPhone application has been "lagging" or rather "frozen" when it got past the start up screen. I think this is due to the registration for remote push notifications is send 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 for retrieving some data and save it to the phone.
So, I would like to send both of these requests asynchronously and have them do two different things in - (void)connectionDidFinishLoading:(NSURLConnection *)connection
. Therefore I need to know which of the two connections that finished.
Is there any way to do this? Would there be any way to distinguish by the URL of the finished connection?
Actually, I thought it would be as easy as set a tag
and check this in - (void)connectionDidFinishLoading:(NSURLConnection *)connection
but this does not seem to be possible.
Does anyone know how I can do this?
As Kalle said, the best thing to do is a class that handles the connection, parses the response, and returns the data in a pretty delegate function.
However if you must for some reason make 2 NSURLConnections with the same delegate, what you want to do is save references to them both in class ivars. Something like NSURLConnection *pushNotificationConnection; and NSURLConnection *someOtherConnection;
Then, your didReceiveData function should look something like:
A clean way to do this is to actually have a separate class handle each request. Or rather, you have a class which is supposed to perform the request, get the data, then send them back (via delegation) to the main class once it's done.
You would thus have two classes, e.g.
PushNotificationRequestor
andSomeLoader
. Each would create and maintain their own separate HTTP (or whatever type it is) requests and would each have their own separateconnectionDidFinishLoading:
etc. methods.