-2

我有 4 个网络服务。我想一次调用这 4 个服务。如何一次调用多个 Web 服务?你能推荐任何关于这个的教程吗?提前致谢。

4

3 回答 3

1

您可以使用 NSOperation 队列甚至 Grand Central Dispatch(取决于您的使用情况)

您必须阅读多线程链接!并自己决定。

于 2014-12-24T06:59:02.957 回答
1
if you are not going to call four web services in the background then it will totally block your                 Application User Interface which results a worst experience to the user so it is better to use Apple Queue based technique to call web services in the background and populate your application interface accordingly.

you should use following  

//调用服务

//set url
dispatch_queue_t queue1 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
//making asynch call
  dispatch_async(queue1,^{

//get your response
       dispatch_queue_t main = dispatch_get_main_queue();
dispatch_sync(main,^{

              //update your view interface with fetched data

           });
 });

此外,当您创建服务方法时,您必须传递 url 和有效负载(如果需要)并设置标头等,因此我认为它将显着提高应用程序性能和交互。

于 2014-12-24T07:04:27.323 回答
1

您可以使用 AFNetworking 进行多请求,https://github.com/AFNetworking/AFNetworking
为什么要在主线程中进行请求,这将导致您的 UI 等待

于 2014-12-24T08:15:29.580 回答