Google/Apple Push Notification Service (APNS/GCM)

29,194

Solution 1

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.

Solution 2

when the device registers with the push service you could create a Unique id (UUID) and then send the unique id to the server along with the registration key and any other information you want. That way you have all the devices the use has and dispatch notifications to all of them

Share:
29,194

Related videos on Youtube

Dmitry R
Author by

Dmitry R

Updated on July 09, 2022

Comments

  • Dmitry R
    Dmitry R almost 2 years

    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?

    • Rok Jarc
      Rok Jarc over 10 years
      You do have device tokens stored somewhere? We store device-tokens and device-types (and app-versions running on devices...) in dedicated table. Each user can thus have as many devices registered as one wants. Notification-worker-threads then know which process & server to use while sending a message to any device. This (token,type,version) is sent to server each time user logs in.
    • Stephen Johnson
      Stephen Johnson over 10 years
      Any reason why you wouldn't use www.parse.com to manage your pushes? It can do a lot of pushes each month for free and it handles all of this for you.
    • abhimuralidharan
      abhimuralidharan about 8 years
    • Arvind
      Arvind over 7 years
      you can test using pushtry.com
  • Dmitry R
    Dmitry R over 10 years
    This sounds valid for iOS devices, but how can I distinguish between iOS and Android devices, I need to make the decision on my server what API to forward the notification to, APNS or GCM. Or just create logic that says if not APSN it's GCM?
  • tyczj
    tyczj over 10 years
    send a flag when you send the information on what type of device it is