I am using subclasses of Ben Copsey s ASIHTTPRequest
very heavily for a web service client I hope to finish in the next couple weeks. It s a great project and his work has saved me a great deal of time and effort.
I have an ASINetworkQueue
set up in the application delegate. The queue is sent the -go
message so that it is ready to receive requests. I add my subclassed requests to this queue. Each request is processed and issues its notifications, and my view controller handles the response data accordingly.
What I have done is subclass ASIHTTPRequest
and:
- Set up an
-init
method (or -initWithParams:
method, depending on the request)
- Override
-requestFailed:
and -requestCompleted:
to handle HTTP error messages coming back from the web service
- My view controllers register to observe
NSNotification
notifications that come from error handling in the -requestCompleted:
method
As view controllers are pushed on and popped off the navigation stack, I add and remove different registrations. Some view controllers only need to listen for certain subclassed request types.
Listening for NSNotification
allows me to issue UIAlertView
dialogs to let the user know something went wrong, or to handle the request response data (feeding results into a Core Data store, for example) when the request yields a successful HTTP error.
Whether the request succeeds or fails, I remember to -release
the request when I m done with it.