Reputation: 1145
I'm working on an app, which allows users to manage (CRUD) content stored on a server. I mirror some of the data in the local storage (Core Data).
When a user deletes or updates a file, I delete it in the local database and send an HTTP request to the server. I don't want to send multiple requests in parallel and I'd like to implement an offline mode. I'm thinking of some kind of a queue which stores the requests and executes them, whenever the device is connected to the internet. If the request fails, the worker should try again, before working on the next request in the queue.
What's the common practice to achieve this? Are there any frameworks with this features?
Upvotes: 1
Views: 2946
Reputation: 7717
ASIHTTPRequest
also has an example of using an NSOperationQueue and their own version of a queue:
http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_queue
This will allow you to queue your requests and process them without blocking your application flow.
To handle an offline mode though, you might need to send them into a "queue" in your database, pull them out when you have a connection (or when the user hits sync) and add them to the your NSOperationQueue
. NSOperationQueue
allows you to suspend scheduling (and reactivate it), but I'm not sure if it could really act like a persistent store of queued up actions.
Upvotes: 3
Reputation: 1414
I believe NSOperationQueue is what you are looking for. https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html
Upvotes: 0