60
votes

I'm developing a chat system for web, Android and iOS. Doing my research I've found differences on how GCM and APNS handle the Push Notifications.

If I send a Push Notification to a Android Device through the GCM, the device its able to decide if it notifies the user about it, or if its not necesary, it doesnt tell the user. It could be just an update of data that the user doesn't need to be notified. On the other hand, if I send a Push Notification to an iOS Device through APNS, the device is not able to decide whether to show or not the notification, the notification must be shown. Also, when an iOS Device receives the notification, the notification data must contain the string that is going to be shown to the user. On Android, the device can generate that string.

So, I wanted to create a system that works the same way for both iOS and Android, and also for the website (API based). Thats when I found Socket.io. Socket.io gives me the freedom to send data to the device (no matter if its iOS or Android) so that the device decides whether to show or not the changes made (could be an update of a user, a new message, an invitation, or many other "events"). But, doing my research I found some cons about using Socket.io. The Device must be connected to the socket so that the information flows between the client and the server, but a smartphone, in the real world, connects and disconnects all the time to different networks, and that breaks the socket connection. Also, by having the connection open, on the background, there is a ping pong between the server and the client to verify that the connection is still open, and that ends up consuming megas (In my country, we pay for every mega we use, we don't have a flat rate yet) and also batery life. I don't know for sure if that consumption is significant or not.

On the web side, it must work with Socket.io, so thats not a problem at all.

Finally, knowing the pros and cons of both alternatives, I found that I can mix both options and that might end up being my best option. For example, when the app is open it uses Socket.io and when is closed use the APNS or GCM (depending on the device OS). But, is it a good practice? Or will it be better to stick just with 1 solution instead of mixing both and why?

Thanks a LOT for taking your time on reading this and even more for answering.

1
This is a great question because there has to be a balance here. I'm actually inspired after reading this because I am building the notifications right now on an app. I'll use node.js socket.io to first detect if they are online. If so, use socket.io to notify, else use notifications for android/ios. Thanks!King Friday
@PDK did you end up using both ?ralphgabb
@ralphspoon I had to use both, is the best way if you want to do the right thing. But at the end, it was a mess to handle the system so I end up moving to Firebase.PDK
thanks ill check what firebase is. thanks @PDKralphgabb
I have to opted for Socket.IO because often it happens that some of the users failed to receive notification from GCM and it happens randomly. I have checked the respective support forum about this issue and found some others also having similar issue. I have finally decided to use Socket.IO and custom reinvent the wheel.codelearner

1 Answers

16
votes

You have listed the pros and cons accurately. Using both will give you more work in terms of maintenance, and also more complexity, but will give you the flexibility you're after. It will boil down to your requirements.

Also you will probably find that having a socket.io connection open in a iOS background process will be troublesome. iOS is much more restrictive in what tasks can run in the background than Android.