AFNetworking的多个请求 [英] Multiple request with AFNetworking

查看:150
本文介绍了AFNetworking的多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在后台执行多个请求以下载许多jsons并检查来自他们的数据但我不知道如何在这种情况下使用AFNetworking。

I'm trying to do multiple request in background to download many jsons and check data from them but I don't know how to use AFNetworking in that case.

我试着做类似Wiki的解释,但是当它要下载第二个文件时,应用程序会中断。我想在后台完成所有这些过程。

I tried to do like Wiki explaings but when it's going to download the second file then the app breaks. I want to do all the process in background.

谢谢

推荐答案

查看 AFHTTPClient 's
enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock: ,可让您将多个请求排入队列同时进行操作,还有一个额外的好处,即当所有这些请求完成时调用完成处理程序,以及跟踪进度的块。另请注意,每个操作仍然可以拥有自己的完成处理程序(例如,如果您必须处理请求的结果,则非常有用)。

Check out AFHTTPClient's enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:, which lets you enqueue multiple requests operations at once with the added bonus of having a completion handler that is called when all of those requests have finished, as well as a block for tracking the progress. Also note, that every single operation can still have its own completion handler (useful if you have to process the results of a request, for example).

如果你不喜欢需要自定义请求操作(并且不需要单独的完成块),您也可以使用 enqueueBatchOfHTTPRequestOperationsWithRequests:progressBlock:completionBlock: ,允许您传递数组直接 NSURLRequest ,无需自行构建操作。

If you don't need to customize the request operation (and don't need individual completion blocks), you can also use enqueueBatchOfHTTPRequestOperationsWithRequests:progressBlock:completionBlock:, which allows you to pass an array of NSURLRequest directly without having to build the operations yourself.

这篇关于AFNetworking的多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆