开发者

Correct way to handle various NSURLConnections differently

开发者 https://www.devze.com 2023-02-22 18:45 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消