简体   繁体   English

iPhone-将数据发送到服务器并使用NSOperationQueue

[英]iphone - Sending data to server and using NSOperationQueue

In my application, i've to send lots of reports to server. 在我的应用程序中,我必须向服务器发送大量报告。 So I created a class SendReport which extends from NSOperation. 因此,我创建了一个从NSOperation扩展的SendReport类。

Now I in my view controller class I will create NSOperationQueue and then create multiple objects and add them to the queue. 现在,在我的视图控制器类中,我将创建NSOperationQueue,然后创建多个对象并将它们添加到队列中。

Now in the SendReport, in "main" i want to create NSMutableURLRequest and NSURLConnection and initiate sending data to server...... also i want to implement delegates for NSURLConnection to observer data transfer and when it is finished..... 现在,在SendReport中的“主”中,我想创建NSMutableURLRequest和NSURLConnection并启动将数据发送到服务器的工作……我也想实现NSURLConnection到观察者数据传输的代理以及何时完成.....

can someone guide me how should i implement "SendReport" class that will transfer data to server and also to implement delegates please? 有人可以指导我如何实现“ SendReport”类,该类将数据传输到服务器并实现委托吗?

Based on what you've written, you're making this process more convoluted then it needs to be. 根据您所写的内容,您正在使此过程变得更复杂,而不是必须如此。 If you are sending files from a background thread then there is no need to send them asynchronously. 如果要从后台线程发送文件,则无需异步发送它们。 Just send them synchronously and you can avoid worrying about delegates and callbacks. 只需同步发送它们,就可以避免担心委托和回调。 If you are going to use NSURLConnection to send the files asynchronously, then there is no need to mess around with an operation queue, just start the files sending from the main thread and use the delegate callbacks to update progress in your UI. 如果要使用NSURLConnection异步发送文件,则无需弄乱操作队列,只需启动从主线程发送的文件并使用委托回调来更新UI中的进度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM