简体   繁体   English

是否可以多次启动NSURLConnection?

[英]Is it possible to start an NSURLConnection multiple times?

I'm setting up a class to manage the download of some data. 我正在设置一个类来管理某些数据的下载。 Due to the spec it has to be downloaded multiple times (as it may change). 由于规格要求,必须多次下载(可能会更改)。 I can't change that but I have a question. 我无法更改,但是我有一个问题。

If I create a class that is dedicated to downloading the data so it is an NSURLConnectionDataDelegate etc... 如果我创建一个专门用于下载数据的类,则它是一个NSURLConnectionDataDelegate等。

Can I store the NSURLConnection as a property and set it up in the init and then reuse the same connection each time? 我可以将NSURLConnection存储为属性并在init中进行设置,然后每次重用相同的连接吗?

Or should I store the NSURLRequest and use the same request in a new connection each time? 还是应该存储NSURLRequest并在每次新连接中使用相同的请求?

The reason I ask is that the docs for NSURLConnection state... 我问的原因是NSURLConnection状态的文档...

"You cannot reschedule a connection after it has started."

and I'm not 100% sure what that means. 我不确定这是什么意思。

Yes, as long as each time you have a unique object that creates the NSURLConnection. 是的,只要您每次都有一个创建NSURLConnection的唯一对象。 This is simply stating you can't have the same object "reschedule" a connection, mid connection. 这只是说明您不能让同一对象“重新计划”连接,中间连接。

Never hurts to run a simple test. 进行简单的测试不会有任何伤害。

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

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