在 iOS 中实现基于一系列异步 ASIHTTPRequest 的工作流程的最佳方法是什么?
我已经为处理基于一系列异步 ASIHTTPRequests 的工作流程(我正在使用队列)的体面方法而奋斗了一段时间。到目前为止,它似乎一直困扰着我,我总是以一堆可怕的委托调用和意大利面条代码在我的项目中爆炸而结束。
它的工作原理如下:
- 下载项目列表(1 个单个 ASIHTTPRequest,添加到队列中)。
- 需要存储步骤 1 中检索到的项目。
- 然后解析从 1 开始的每个项目,为每个项目的子项目排队 1 个 ASIHTTPRequest。
- 处理来自步骤 3 的每个请求并存储子项。
我需要能够使用进度百分比和消息更新用户界面。 我一生都无法找到一种干净/可维护的方法来做到这一点。
我查看了以下链接:
但要么我遗漏了一些东西,要么它们似乎没有充分描述我想要实现的目标。
我可以使用块吗?
I've been fighting and fighting for some time with a decent way to handle a workflow based on a series of asynchronous ASIHTTPRequests (I am using queues). So far it seems to have eluded me and I always end with a hideous mess of delegate calls and spaghetti code exploding all over my project.
It works as follows:
- Download a list of items (1 single ASIHTTPRequest, added to a queue).
- The items retrieved in step 1 need to be stored.
- Each item, from 1 is then parsed, queuing a 1 ASIHTTPRequest per item, for it's sub-items.
- Each of the requests from step 3 are processed and the sub-items stored.
I need to be able to update the UI with the progress %age and messages.
I'm unable for the life of me to figure out a clean/maintainable way of doing this.
I've looked at the following links:
- Manage Multiple Asynchronous Requests in iOS with ASINetworkQueue
- Sync-Async Pair Pattern Easy Concurrency on iOS
But either I'm missing something, or they don't seem to adequately describe what I'm trying to achieve.
Could I use blocks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现自己面临着一个非常相似的问题,因为我在一组流程和工作流程中使用一组异步 http 和 ftp 处理程序来练习开发应用程序。
我不知道 ASIHTTP API,但我假设我做了类似的事情。
我定义了一个所谓的 RequestOperationQueue,它可以代表某个工作流程的所有请求操作。我还定义了几个模板操作,例如 FTPDownloadOperation。线索来了。我或多或少地根据 http 的想法实现了所有这些 RequestOperations ://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/。我没有在操作本身中实现委托逻辑,而是实现了专门针对不同协议(http、ftp、rsync 等)的回调处理程序,为特定请求提供状态属性,该请求可以由操作通过 KVO 进行处理。
例如,可以通过 RequestOperationQueue 的委托协议向 UI 通知有关工作流程的信息。例如 didReceiveCallbackForRQOperation:(RequestOperation) rqo。
从我的角度来看,通过这种方法,包括客户端-服务器操作在内的工作流编码变得非常方便。
I see myself facing a quite similar issue as I got the exercise to work on a app using a set of async http and ftp handlers in a set of process and workflows.
I'm not aware about ASIHTTP API but I assume I did something similar.
I defined a so called RequestOperationQueue which can for example represent all request operations of a certain workflow. Also I defined several template operations for example FTPDownloadOperation. And here comes the clue. I implemented all these RequestOperations more or less accroding to the idea of http://www.dribin.org/dave/blog/archives/2009/05/05/concurrent_operations/. Instead of implementing the delegate logic in the operation itself I implemented sth like callback handlers specialized for the different protocols (http, ftp, rsync, etc) providing a status property for the certain request which can be handled by the operation via KVO.
The UI can be notified about the workflow for example by a delegate protocol for RequestOperationQueue. for example didReceiveCallbackForRQOperation:(RequestOperation) rqo.
From my point of view the coding of workflows including client-server operations gets quite handy with this approach.