ios - Chain of POST requests in Objective C (iPhone) -


i need send server set of requests data. data in subsequent requests determined based on server response in earlier requests. not want use synchronous approach nsurlconnection class, limiting (for 1 of requests, instance, need prevent redirects. according apple dev documentation can done delegate implementation).

depending on request in chain is, need doing different things (send different messages various classes).

the way see now, have either create n delegates each of requests, or create delegate initwithflag , create instances of delegate different flags, or need use factory pattern pretty similar solution second one.

i not want implement delegate @ all, want send requests least bit of coding possible. not looking @ frameworks (asihttprequest etc), native classes.

what best approach?

i know said don't want use third party frameworks, i'd suggest afnetworking. said, not need afnetworking or third party library, make life easier imho.

so, have done in similar scenario use command pattern. when want send off 1 of these complicated "requests" initialize command object, set of necessary parameters , call execute. command object has completion , failure handlers/blocks , execute asynchronous call.

within command have different 'steps' synchronous , depend on each other. let's request depends on b , b depends on c, first step of command execute on it's own queue (i using gcd private queue) , wait finish. once finishes (successfully) continue on b , pass in results need b. likewise b->c. if of intermediate requests fail throughout process can execute failure block , handle executed command (consumer end). if finish execute success block.

i prefer encapsulation of approach easy re-use throughout project, of intricacies tucked away in command's implementation.

oh , fact use callbacks/blocks did not need implement delegates. in case using nsurl classes command object delegate of of instances.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -