Long-polling vs Apple Push Notification Service &

2019-02-08 15:31发布

问题:

I am building a mobile application that has some realtime constraints. Therefore I turn to stackoverflow to get advices & opinions and attempt to decide which is the best solution to update the state of the application while running:

  1. rely on long-polling or direct connection to my server
  2. rely on Apple Push Notification Service and Android C2DM

Beyond the fact that APNS and C2DM provide a unified interface to push notification while the application is running or not, one can say that a custom solution (based on long-polling or a direct connection) is more flexible and less dependent on the latency of Apple & Android queues.

As far as I can see, I think most of the debate stems from the cost comparison of how much battery it consumes to keep a connection opened compared to opening a connection on a smartphone.

I am therefore particularly interested in two things:

  • Experiences with APNS and C2DM
  • Details on all the implications of keeping a TCP connection open on a smartphone.

References welcome! Thanks!

回答1:

dependent on the latency of Apple & Android queues

I don't think that's true. It's up to the app developer and the server side implementation how much time this takes. I get my email pushed to my phone before my browser client gets it. And not just gmail, my corporate e-mail as well.

As for your question, you should work with whatever works best. Or even better, you should give the user the option to use push notifications or to set the polling period.