Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google/Apple Push Notification Service (APNS/GCM)

I'm trying to create application for Android and iOS and I want to use push notification on both the application. I'm going to have a server app that will be sending the notification.

What I'm trying to figure out is how we can store the device of the user so I'll know which service need to be used APNS or GCM.

One of the directions is to get the phone type to be set by the app and store this information on the server side, but what happens if the user changes his phone from iOS to Android, need to involve data storage of the user and collect information for every user, not covers scenario when user has Android tablet and iOS phone.

Make it more generic and dispatch the notification to both services APNS and GCM at the same time, one of them will return error?

Would love to hear what is the best practice for such scenarios?

like image 613
Dmitry R Avatar asked Dec 19 '13 15:12

Dmitry R


People also ask

What is APNs and GCM?

Both Android and iOS requires the device to contact their respective push message provider (GCM or APNs) to receive a special string (which I will call the identifier), that uniquely identifies a specific app on a specific device. In GCM this is called the device ID, while APNs calls it a device token.

What is GCM in iOS?

Google Cloud Messaging is a free service introduced by Google to send push notifications to users' device and to send message from users' device to server (GCM). GCM enables developers to transfer data from servers to both Android and iOS apps.

What is GCM push notification?

Google Cloud Messaging (GCM) was a mobile notification service developed by Google that enables third-party application developers to send notification data or information from developer-run servers to applications that target the Google Android Operating System, as well as applications or extensions developed for the ...

What is difference between GCM and FCM?

FCM is the new version of GCM under the Firebase brand. It inherits GCM's core infrastructure to make sure we continue to deliver messages reliably on Android, iOS and Chrome. Show activity on this post. FCM is the new version of GCM under the Firebase brand.


1 Answers

It is very simple to implement APNS and GCM:

  • When APNS (iOS Devices) and GCM (Android Device) registers for Push Notification on Apple and Google Server it generates a unique token for every device.
  • After that, you need to save that device token, with your device id or user id (unique id on your server for device) and the OS of device.

Like and iOS device is sending this information on your server (backend) you can use this JSON format- {"token":"abcdedfgehik2bd3d3ff3sffssdff","os":"iOS","userid":34}

For android device it will be - {"token":"erydnfbdbdjskd76ndjs7nnshdjs","os":"Android","userid":35}

By this you can identify the OS of device, as well as user information and unique token which will be used for sending push notification.

like image 179
Devel Avatar answered Oct 18 '22 21:10

Devel