Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS job queue similar to Path's android priority job queue

Does anyone have an iOS job queue similar to Path's Android Priority Job Queue that they don't mind sharing with the community? I am very new to iOS so I am not sure if the platform itself provides such a solution. On android no such thing exists so I had to use the library that Path has generously made available. If iOS itself or Xcode has such a solution/API please point me to it. If not please share yours if you don't mind. Thanks.

Basically I am looking for a job queue that can allow users to send data to server even when there is no network: which means the queue would hold on to the data even if user should turn off the iPhone. And then at some later time, when the system detects network, push the data to the server.

There is a similar question on SO already so I am including it for more detail: How to queue up data for server dispatch on android. The difference is that my question is for iOS and theirs is for android.

Use case

My case is imagining a user is boarding a train in a subway (no network) but decides to send an email. Then close the app, or even turn off the phone. Then an hour later, after user turns phone back on, when network is detected, the app sends the email.

like image 234
Katedral Pillon Avatar asked Oct 20 '22 05:10

Katedral Pillon


2 Answers

https://github.com/thisandagain/queue is quite promising. It has ability to retry and is persistent.

like image 196
Arkhitech Avatar answered Oct 22 '22 23:10

Arkhitech


AFNetworking's request operations and request operation manager could be modified to do this with not too much work.

Needed modifications:

  • When an AFHTTPRequestOperation fails due to no connectivity, make a copy of the operation and store it (in an NSArray, for example)
  • Use the built-in reachability manager, and retry the operations in the array when reachability returns
  • Remove the operations from the array if they're successful

Note that the completion blocks aren't copied when an operation is copied. From the documentation:

  • -copy and -copyWithZone: return a new operation with the NSURLRequest of the original. So rather than an exact copy of the operation at that particular instant, the copying mechanism returns a completely new instance, which can be useful for retrying operations.
  • A copy of an operation will not include the outputStream of the original.
  • Operation copies do not include completionBlock, as it often strongly captures a reference to self, which would otherwise have the unintuitive side-effect of pointing to the original operation when copied.

I don't know of any open source library that has already implemented these modifications, or I'd point you there.

like image 30
Aaron Brager Avatar answered Oct 23 '22 01:10

Aaron Brager