Home » Android » One server sending push notifications to Android and iOS devices

One server sending push notifications to Android and iOS devices

Posted by: admin June 15, 2020 Leave a comment


Our organization has an Android app and an iOS app.

We want to start pushing notification to these apps.

Android has GCM.
Apple has APNS.

But we want to create an API which will work on both android and iOS.

What is the easiest way to setup a server so that when a push notification needs to be sent, it knows exactly which server to send the message to?

How to&Answers:

As a little background this is for a university setting where multiple colleges apps as well as distance education may be using the service. Here is the approach that we are using in our organization. If you look at the way APNS works it can be used by just sending a web call to the APNS service with the token id. GCM is very close to the same type of system. Basically create a JSON package and send it to the desired service.

Here is our steps we used to create this service.

  1. Server admins created a server and database that can be called that will collect the tokens from both android and ios devices. When the device registers we also send what type of device it is. This is possible since we are just sending data to the database that is has been created.

  2. From here we then created a couple of python scripts that send the data do the desired service whether it is ios or android. These scripts gather the appropriate data from the database and sends the packaged data (JSON package) to APNS for ios message and GCM for google cloud.

  3. We also created a web interface so that those who need to send messages to the devices can.

The rest of the implementation is up to you to decide the best way to utilize the service. For example when to check for invalid devices,
Because we are planning on using this same server for multiple applications we can send the type of device, token, application, or whatever else is needed for an application to distinguish it from others we produce so that each application that wants to use the service can. I hope this helps and gives you some idea on how to accomplish this.


I use a service called Parse to do my notification pushes to both Android and iOS. They have great documentation and libraries available. You can get some details here: https://parse.com/products/push


For APNS, Maybe you may consider this forked version of PyAPNS that has enhanced message support.
which means it will catch error response for failure messages and resent the message which are discarded by APNS while sending between failure messages and receiving error response.


  • Non-blocking ssl socket connection to send notification without waiting for response.
  • A separate thread for constantly checking error-response from read connection.
  • A sent notification buffer used for re-sending notification that were sent after failed notification, or arbitrary connection close by apns.
    (Reference to non-blocking apns pull request by minorblend, enhanced message by hagino3000)


  • Send notification at throughput of 1000/secs
  • In worse case of when 1st notification sent failed, error-response respond after 1 secs and 999 notification sent are discarded by APNS at the mean time, all discarded 999 notifications will be resent without loosing any of them. With the same logic, if notification resent failed, it will resent rest of resent notification after the failed one.

For GCM, you may consider https://github.com/geeknam/python-gcm

For generic wrapper that support both or more mobile provider: