IPhone: loading queue at startup

I have not found an answer to this question anywhere, but this seems like a typical problem:

I would like to send some POST requests (with ASIHTTPRequest, which I already do), but if something goes wrong, the user can decide "Try later", then the task must be queued and this queue should be read the next time you start the application. So my question is: how to โ€œsaveโ€ the queue so that the application can read it next time? Is it possible to "read" the queue and try to send this POST request again, for example, after 10 minutes, even if the application does not work?

What documentation should I read to be able to do this?

I would be very happy to hear any answers. Thanks in advance.

PS: I have another idea: since I just need to upload photos, I may have a folder with all the photos that still need to be downloaded, and when the application starts, the application looks at this folder and tries to send all the photos in this folder. Does it make sense?

+4
source share
2 answers

My approach to this problem will be as follows:

  • Whenever you cannot send data - write the contents of the array to a file using "[NSArray writeToFile:]", you can use serialization if the array contains any data that is customizable (if your array contains standard cocoa objects NSString, NSData etc.) They are already implemented with serialization)
  • When the application starts; load contents from a file directly into an array object ('[NSArray arrayWithContentsOfFile:]')
  • then create an http request and try sending. In the application, data (in your case array) is saved / serialized not by request, you need to restore the http request when you want to try again (do not try to serialize ASIHTTPRequest, you restored it)
+2
source

I assume you already looked at NSOperationQueue and NSOperation . AFAIK there is no built-in support for NSOperation serialization, but you can very easily write your own serialization engine for the NSOperation subclass that you use to publish data, and write the NSOperationQueue operations file to disk if something goes wrong.

Without knowing too many details, it is difficult to give an exact answer. There are many ways to write data to disk and load it later, the direction you take will largely depend on your situation.

+2
source

Source: https://habr.com/ru/post/1316005/


All Articles