Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices in iOS for polling a webservice about task completion

Let's say we have an iOS app that communicates with a web service. Some requests are delegated to another web service, so that a HTTP 200 status code is returned immediately while the operation is in progress on the other side:

|iOS app|          |Main service|    |Delegate service|   
    |     request        |                    |
    |------------------->|_      delegate     |_
    |                    | |----------------->| |
    |     HTTP 200       | |     accepted     | |
    |<-------------------|_|<-----------------| |
    |                    |                    | |
    |                    |                    | | 
    |     status?        |                    | |
    |------------------->|_                   | |
    |                    | |                  | |
    |     pending        | |                  | |
    |<-------------------|_|                  | |
    |                    |                    | |
    |                    |      finished      | |
    |                    |<-------------------|_|
    |                    |                    |
    |     status?        |                    |
    |------------------->|_                   |
    |                    | |                  |
    |     finished       | |                  |
    |<-------------------|_|                  |
    |                    |                    |
    |                    |                    |

These requests can last from 20 seconds up to 2 minutes so we can afford to poll the server every 15-20 seconds.

Which are the best practices to implement such scenario? Could Apple reject the app if we decide to implement a polling strategy of one request every 20 seconds limited to 6 requests?

Unfortunately there is no server support either for a long polling strategy (it's not under our control). The server simply returns a status JSON on each request.

We are trying to avoid using push notifications, since these requests are kind of low-level tasks and the user does not have to be explicitly involved.

like image 420
elitalon Avatar asked Nov 03 '22 00:11

elitalon


1 Answers

I would recommend you to try a Long Polling strategy, which has been discussed in previous threads : long polling in objective-C . Also have a look at this TCP-based RPC server (Erlang or something similar?) for iOS/Android app communication

like image 111
Javier Quevedo Avatar answered Nov 11 '22 18:11

Javier Quevedo