我有4个网络服务。我想一次拨打这4项服务。我怎样才能一次调用多个Web服务?你能建议任何有关此问题的教程吗?提前谢谢。
答案 0 :(得分:1)
您可以使用NSOperation队列甚至Grand Central Dispatch(取决于您的使用情况)
您必须阅读multithreading link!并决定自己。
答案 1 :(得分: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和有效负载(如果需要)并设置标头等,所以我认为它将显着增强应用程序性能和交互。
答案 2 :(得分:1)
您可以将AFNetworking用于多请求,https://github.com/AFNetworking/AFNetworking
为什么你想在主线程中做请求,这将导致你的UI等待