I have an iPhone programming making many different NSURLConnections to a server. I use many different webservices, and for each I get a different response.
This means I make many different NSURL connections and I receive many different types of data back.
I have one class handling all my communications. i.e. one class with all the methods to access the webservices.
For every webservice I need to handle the data differently. As of now I have a saperate NSURLConnection delegate wich handles the:
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response;
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data;
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error;
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
functions. However, I want something different to be executed depending on the webservice I access.
Do I just need to make a different connection delegate for every webservice 开发者_开发技巧I want to handle?
Is there a better way to do this?
Thanks in advance.
You just need to examine the NSURLConnection that is passed into the method. That object corresponds to the connection which the method was tripped from, and you should be able to use that to figure out what web service it came from.
精彩评论