5

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.

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • Have you looked into Grand Central Dispatch? https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html – BergQuester Jul 09 '14 at 17:55
  • @BergQuester I have elaborated on my question. The `Dispatch Queues` iOS provide are for async only. They don't seem to save data to file system and then keep trying to send them until they are sent. Am I wrong about that? Can they handle unfavorable network connectivity issues: i.e. keep data and dispatch when there is network available? – Katedral Pillon Jul 09 '14 at 18:14
  • I apologize for offending 2 people with my question. But please elaborate on why you want the question closed: perhaps I could clarify for you; especially the person who down voted. – Katedral Pillon Jul 09 '14 at 18:17
  • @KetedralPillon GCD is quite powerful and there are synchronous options and cross-queue coordination options. That being said, there may be a better tool for this use case such as Aaron Brager's AFNetworking solution. – BergQuester Jul 09 '14 at 20:07

3 Answers3

2

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

Arkhitech
  • 475
  • 3
  • 11
1

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.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
0

I found very simmilar lib like path's job priority queue

https://github.com/lucas34/SwiftQueue/wiki

Hope this helps someone since this is very old questions but ot might help someone who is still finding like me :)