Best practices in iOS for polling a webservice about task completion
Asked Answered
O

1

6

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.

Otti answered 10/4, 2013 at 7:50 Comment(1)
I'm not sure this is the best place for this question. You may want to try the "Programmers" site from StackExchange (programmers.stackexchange.com)Androsterone
C
2

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

Carree answered 10/4, 2013 at 9:21 Comment(3)
Unfortunately there is no server support for a long polling strategy (it's not under our control). The server simply returns a status JSON on each request. I'll update the question to clarify this.Otti
Well, in that case I guess that there is not too much you can do about it, other than continuously poll the web service. Just do so in a "moderate way", pretty much like you said, waiting some time in between each poll and doing it for a max number of times. An alternative would be to create a facade kind of webservice which does the annoying polling part, to with you can communicate using a socket for instance to avoid polling from the app itself. Just an idea which would allow you to get rid of the polling from the iOS app.Carree
There is a way to schedule polling task when it is convenient for the system to perform it (e.g. radio is on, batch network requests, etc.) on Android. Is it possible to do something similar on iOS?Essy

© 2022 - 2024 — McMap. All rights reserved.