Reputation:
I am attempting to use ASIHttpRequest with the iPhone to get some information from a query-string based API on my site.
Currently, I am in the planning stages of my design and I am kind of stuck on how I should proceed.
I would like to have a class, that will handle all of the requests I will need. I plan on having different sections of the iPhone application call this class and within the class, I would like to run the ASIHttpRequest code. For example:
This is where I am stuck. I would like to somehow pass the responseString back to the original caller of the network url request.
Should I use a delegate method? If so, how can I call that from within the requestFinished method? I thought about this, but I am a little confused as to how I would have the requestFinished function call that delegate. I might be missing a simple way to pass that delegate as an object along with an ASIHttpRequest.
I also thought about NSNotificationCenter, but I feel that would be more work than using a delegate.
I appreciate any help given.
Upvotes: 0
Views: 1271
Reputation: 17170
You can subclass ASIHttpRequest and either override its - (void)requestFinished
which allows you to do some processing on the background thread (and still call [super requestFinished];
) or simply add an instance variable id myDelegate;
with an accessor so you can access it from your -requestFinished
Upvotes: 0
Reputation: 10860
It depends on what do you want to do with response. If you just want to show an alert message with response you can do it directly in your request delagate method. Another way is to store your responce in class with share data and post a notification to tell the listener that it has data to process. It's not difficult) And the third variant. You can create a basic class for your client-server communication with delegate and selector properties. And then just call [delegate performSelector:selector] if you need it. Then you can inherit other classes for login, checking versions, etc.
Upvotes: 1