如何在xcode中调用多个webservice
我想从不同路径的 url 下载 10 个不同的视频,假设我的 url 是 http://someurl/document /path1.mp4 直到path10.mp4。我想通过http连接post方法来做到这一点,是否可能以及如何做。如果我这样做,我需要创建connetion1,连接2......连接10跟踪我在 connectionDidreceive Response 方法中获得响应的(连接)数据。
基本上想要的是一起下载视频,也就是说我不想像下载第一个视频然后第二个然后第三个那样做,但我想要的是开始同时下载所有视频这可能吗?如何?
I want to download say 10 different video from a url at different path,lets say my url is http://someurl/document/path1.mp4 upto path10.mp4 .I want to do this by http connection post method , is it possible and how .If i do by this do i need to create connetion1 , connection 2....... connection10 to keep track for which(connection) data i am getting response in connectionDidreceive Response method .
Basically what is want is to download the video alltogether that is i dont want to do like downloading 1st video then second then third but i what i want is to start download all the video at same time is that possible and how ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 NSOperationQueue 进行并发下载。 http://www.cimgf.com/2008/ 02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/ 或查看 ASIHTTPRequest http://allseeing-i.com/ASIHTTPRequest/How-to-use 查找ASINetworkQueue示例:https://gist.github.com/150447
You can either use NSOperationQueue's for concurrent downloads. http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/ or look at ASIHTTPRequest http://allseeing-i.com/ASIHTTPRequest/How-to-use Look for ASINetworkQueue example:https://gist.github.com/150447
这当然是可能的。
如果您正在寻找一种管理这些多个请求的好方法,而不仅仅是开始并放任它们;我相信这个线程可能会阐明这个问题。它似乎强调了一些管理多个请求的建议,您可能会发现这些建议很有帮助。
This certainly is possible.
If you're looking for a good way to manager these multiple requests, and not just start and let them be; I believe this thread may shed some light on this issue. It seems to highlight some recommendations for managing multiple requests, which you might find helpful.
如果您有文件 URL,那么您可能不需要 post 方法。当您向服务器发送一些参数时,会专门使用此方法。
Well ConnectiondidReceiveResponse 在响应已到达的参数中发送连接对象。
最佳实践是编写一个具有一个连接对象的类,并使用不同的 URL 和文件特定参数(如保存位置等)初始化 10 个这样的类。然后该类将处理下载的所有复杂性。完成后,它可以用文件名通知调用者类。 。
If you are having file URL then may be you won't need post method. This methods are specifically used when you you send some parameter to server.
Well ConnectiondidReceiveResponse send connection object in arguments whose response has arrived.
Best practice would be to write a class which will have one connection object and init 10 such class with different URL and file specific parameter(Like save location etc). Then that class will handle all complexity of downloading. and at end of completion it can notify the caller class with file name.