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?
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
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.
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.
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.
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.
For APNS, Maybe you may consider this forked version of PyAPNS that has enhanced message support.
https://github.com/jimhorng/PyAPNs
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.
Solution:
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)
Result:
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:
https://github.com/Redth/PushSharp
Related
According to the Firebase Cloud Messaging documentation if the app server sets a field "delivery_receipt_requested" in the upstream message, it will receive a delivery confirmation when the app confirms receipt. However it works only if app server is connected with XMPP connection server. It will not work for HTTP connection server.
I'm very new to GCM/FCM and haven't setup my server yet. Hence am working with Firebase console to test my app for notification receipts.
So, following are my queries.
Will the field "delivery_receipt_requested" be sent to the app or the connection server itself will consume it.?
If the app receives this field in a notification will it need to act differently from the notification which do not contain this field.?
Any references to documentation or example implementation which makes use of this field is highly appreciated.
Thanks in advance.
Will the field "delivery_receipt_requested" be sent to the app or the connection server itself will consume it.?
The FCM client installed in Google Play services will handle this.
The application will not notice anything different.
If the app receives this field in a notification will it need to act differently from the notification which do not contain this field.?
The application doesn't need to take any action. indeed the app will not receive this field.
Longer explanation:
delivery_receipt is not exactly a confirmation that the app received the message, but it's a confirmation that the device received the message. To be clear it's still possible that the device crashed or run out of battery while the message is being passed to the app.
this feature is implemented outside of the application. so the application doesn't need to be aware that this message requires a delivery receipt
you can implement a more precise "application delivery receipt" by calling your backend in the method that receives the message.
(like an http call to: http://mywebsite.com/confirm-msg-processed-successfully.php?id=133)
I am doing a prototype that involves messaging between clients.
What I want to do - from MyApp on device1, able to send message to MyApp on device2. Device2 should receive this and show a notification.
I don't have my own application server to push notifications from GCM to GCM clients.Is this possible ? How to do it ?
What I investigated - PubNub, which has a trial license that seems to answer my need to send messages on a channel without needing a server.
This discussion at SO didn't help much.
sending client to client messages without server interaction
Can anyone suggest better ways ?
You basically have to use a server in one way or another. I think Firebase would be perfect for your purposes. It has an Android plugin you can use that will basically alert your app when something changes in the database. Here is the documentation for that feature. Take a look at this example for implementation. Before you can use the plugin, you need to create an account and whatnot (basic one is free). Here are the instructions.
PubNub Realtime Messaging and Push Notifications
(server not required)
With PubNub, you do not need your own server to do the realtime messaging or the mobile push notifications. You likely have your own server for your database (MySQL or similar, traditional RDBMS, a No SQL DB like MongoDB, or a realtime DB sync, like Firebase) to authenticate users and such.
For realtime DB or non-DB type change notifications and signaling (any type of realtime messaging), PubNub makes is super simple to receive messages in realtime with a mobile push notification fallback in one publish action. So the GCM message will be sent along with the realtime message. If the app is actively running, you get it in realtime (< 1/4 on average - typically faster) and the GCM message will be received if the app is not active (background or not started at all).
And PubNub's free plan is not a trial (anymore). It is free (including all add-ons) for as long as you stay within the free plan limits.
See the PubNub Android docs for more details and contact PubNub support if you have any further questions with getting started or getting answers to any questions you have as you progress with your app implementation.
Another possibility is to use the SMS.
Android Send and Recieve Messages
"Send Binary (Data) SMS
We can send binary messages (as opposed to text based messages that we covered earlier) to specific application ports using sendDataMessage(). According to this Stack Exchange thread data sms is one which is sent over 2G/3G as well as GSM. I’ve tested it with mobile data turned off and it works fine charging me the same amount, so not very sure on whether it uses 2G/3G or not, but generally the term data is used in telephony when it’s related to network (tcp/ip). Anyway, SMS’s are generally sent to a specific port on the device (which is probably port 0 [zero]). But using sendDataMessage() we can send SMS’s to some other random port on which our app can listen for incoming SMSs and do something with that. In this case the default messaging app will not store the SMSs in their inbox for both the sender as well as the receiver.
"
I'm totally new to hybrid world so I have to ask first.
Can I send notifications through GCM without a server?
I mean, I'm building a SPA with AngularJS and Firebase, but my customer asked me to make a dashboard for Android, so every time an user makes an order, they (both dashboard administrators) receive a PUSH notification on their phone: "A new order has been created", and when they "tap", the application opens.
I've been reading something about /topic/ endpoint to notify both of them, but I think I still need a server to do it. Do I?
It would be great if I simply post a http query using something like AngularJS' $http service to tell GCM to send a notification for that topic/usergroup.
Is that possible? If so, any idea about how?
Thank you very much in advance!
Sending a downstream GCM message can be done "without a server". One option is to send an HTTP request to GCM containing the required fields. Topic Messaging is available with GCM which does make it easier to send downstream messages without a server. Your client apps can subscribe for messages from /topic/usergroup and then you can send an HTTP request with /topic/usergroup as your "to" value, and subscribed clients will get it.
Note that you will need to set up a Google Developer Console project to get the required API key.
Check here for more information on the structure of GCM HTTP downstream messages.
I have an android app which i connect to my server using REST API (django rest framework)
here is a scenario(and maybe my plan):
data is sent back and forth as json
I have a user model and a task model where users are owners of some task.
Users typicaly sends a task to another user (with json similar to this: {"owner": "exampleuser", "from":"otheruser", "content":"example" ...} using POST method)
-The tasks has a boolean field "completed" and is deleted once the task is completed (using PUT or PATCH method: completed = true,)
once a new task gets created using POST method, the only way users can see any activities concerning their tasks is through an android activity that uses GET method to get a list of all the tasks owned by the user, by looking up all objects owned by the user
So my questions are:
Instead of having the user to check the app everytime. How can I use GCM to push notify the user?
How will it tell which user or device to send the push notification to?
How does GCM knows when there has been a change to tasks or when a user POST a task?
Android keeps one active connection to Google's servers, but it doesn't use much power or data, because no traffic is sent along it until something sends a GCM message to an app on your phone. There's only one connection on the phone, used by all apps: installing a new app that uses GCM doesn't add any extra load.
The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app. The app must have registered with Android to use GCM, and it must have the relevant permission. When the app starts, it might create a notification straight away with the data from the message. GCM messages are very limited in size, so the app might instead open a normal connection to the third-party server to get more information (for example, downloading the headers of new emails).
The advantage of using push notifications is that apps don't have to run at regular intervals to check for new data, saving both power and data. The advantage of having a centralized mechanism like GCM is that the device only needs one open network connection and the Android GCM system is the only thing that needs to keep running, rather than each app having to stay running in the background to keep its own network connection to its own server.
As per the GCM implementation, it requires that you implement a remote server which will manage all the requests, both incoming and outgoing. You can do this simply with a web server acting as a webservice, which will get (for instance) the requests from the clients with a HTTP POST request, and process act consequently.
Instead of having the user to check the app everytime. How can I use GCM to push notify the user?
This will be managed by the server that I just described. It will know who is subscribed and who should receive the notifications.
How will it tell which user or device to send the push notification to?
Same goes here. The server, upon a subscription, should store the users in some kind of storage (a SQL database, for instance), and this way it will know who to send notifications. This implies you'll have to implement some timeout mechanism. In my case, I make clients send a dummy HTTP POST every 30 seconds. If I don't get this request from a reasonable amount of time, I consider the client timed-out and therefore I remove them from the database.
How does GCM knows when there has been a change to tasks or when a user POST a task?
Same story, it's all handled by the server. You implement the logic of what should happen upon any request.
You might want to read this: How to send location of the device on server when needed
And also this references:
Reference on Google Cloud Messaging
Android Push Notifications using Google Cloud Messaging GCM - Android Example
Google Cloud Messaging using PHP
Connection between PHP (server) and Android (client) Using HTTP and JSON
Notificaciones Push Android: Google Cloud Messaging (GCM). Implementación Cliente (Nueva Versión) (spanish)
I am developing mobile client for emailing service. One of the key features is notifications about new messages in the mailbox. As recommended by GCM architecture guidelines we are using a "Pusher" that is responsible for sending messages to the Google servers once we received a new message. The issue is that testing process has reported about serious problems with push notification delivery to devices.
So the question: is there an approaches for monitoring average statistics about push notification delivery percentage, time etc? Or maybe somebody have experience in how to set up test environment for efficient monitoring of how much notifications are getting lost during the application work?
All the "tips&tricks" related to the improving Android GCM experience are welcome.
Google claims that the processing at their GCM server takes less than a millisecond. Link below for a great video on GCM from Google's developer. And it's believable coz I could get push notifications almost instantaneously using my company's server to my device now.
http://www.youtube.com/watch?v=YoaP6hcDctM
They don't guarantee delivery, but they try for a max of 4 weeks to deliver the message depending on the duration you set in the message you send to Google's GCM servers and if you wish to let Google keep the data for eventual delivery of message to the device in case the device was offline when the message was to be delivered.
However, there are certain conditions under which the GCM messages are not delivered.
Background data is unchecked under Account and Sync settings.
Prior to 4.0.4.(ICS), a Google account on the device is a pre-requisite for GCM. Maybe, Users are not logged into their Google account.
The only way to do so is to report back to your server with the timestamp of the received push.
You can either
Report back to the server once you receive the notification in your GCM service. To implement, you will have to add a push id for your push notifications and send the id along with the push data. The client will have to get the timestamp once it receive the message and send it back along with the notification id. A simple php script can be done (when you send a push notification, you set the time of the send-notification and once it receives the device's timestamp it sets the receive-notification. This boils down to two fields in your database (marked in bold). In this approach you will probably not so much care about errors since it is very probable that the device will have a connection when it receives the notification and as such its request to your server will go through.
Keep a list of notifications received in your app and their timestamps. And when the sync is done, send the this data in your sync operation. This is ultimately the same approach but your server's data won't be as realtime as the first approach. However, the extra request is not required from the client's side but saving the received notifications and their timestamps is.
All in all, you will have to keep track of the notifications sent using a notification-id and their sending time (send-notification) and their receive time (receive-notification). A simple query will help you analyze this data.
Google has added support so that you can receive delivery receipts from Cloud Connection Server (CCS):
You can use upstream messaging to get delivery receipts (sent from CCS to your 3rd party app server) when a device confirms that it received a message sent by CCS.
To enable this feature, the message your 3rd-party app server sends to CCS must include a field called "delivery_receipt_requested". When this field is set to true, CCS sends a delivery receipt when a device confirms that it received a particular message.
https://developer.android.com/google/gcm/ccs.html#receipts
Google does not make these statistics available to you. There are some statistics available on the android developer console. This only shows the number of messages and registrations.
You would have to implement your own data collection, which could be done fairly easily. You could record the time & id of each message sent and have your android client report back to your server with the time of message receipt. You could then store the data on your server and query as needed.
Since that time Google has provided developers with advanced monitoring tool.
The Gcm Diagnostic Tool is available in Google Play developer console. Additional information is here https://support.google.com/googleplay/android-developer/answer/2663268
So you can easily track the particular message status via registration token.