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.

elitalon
  • 9,191
  • 10
  • 50
  • 86
  • I'm not sure this is the best place for this question. You may want to try the "Programmers" site from StackExchange (http://programmers.stackexchange.com) – rdurand Apr 10 '13 at 07:54

1 Answers1

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

Community
  • 1
  • 1
Javier Quevedo
  • 2,066
  • 1
  • 17
  • 27
  • 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. – elitalon Apr 10 '13 at 09:40
  • 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. – Javier Quevedo Apr 10 '13 at 09:45
  • 1
    There is a [way to schedule polling task](https://developers.google.com/cloud-messaging/network-manager) 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? – surlac Apr 15 '16 at 17:47