Simpler push-notification, perhaps ask server if t

2019-03-03 09:01发布

问题:

Im working on a ide where I as an admin can send notifications to all my clients(mobile). Ive been searching and found GCM and other services... I want to know if there is any simpler solutions.

I thought about making a rest call from all clients(mobile) to my server every 1 hour to check for new notifications. And if there is, get them and then present those notifications i the clients(mobile).

回答1:

Polling will result to more battery life consumption and some other extra unnecessary process (as also mentioned in the comments by @MohammedAtif), for example, is when your client app makes the call to your server but ends up empty. The process is wasted since nothing really happened.

GCM doesn't do that. Gonna refer to the official docs on it's flow.

Lifecycle Flow

  • Send and receive downstream messages.
    • Send a message. The app server sends messages to the client app:
      1. The app server sends a message to GCM connection servers.
      2. The GCM connection server enqueues and stores the message if the device is offline.
      3. When the device is online, the GCM connection server sends the message to the device.
      4. On the device, the client app receives the message according to the platform-specific implementation. See your platform-specific documentation for details.
    • Receive a message. A client app receives a message from a GCM connection server.

Also announced in the recent I/O 2016, GCM's successor is now Firebase Cloud Messaging, which not only has the Push Notification Service, but also has other features (one example is Analytics) for free.

So overall, using GCM (or FCM) is a simpler method than polling. It handles the queuing of the messages you sent, and some others.