Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send push notifications to multiple users using GCM

I followed some demo's and its working fine in my mobile. But i have some questions. Is Registration Id is unique for application or user? If it is unique for user then how to save multiple regID's in server(dot net). Please give me some guidance.

like image 329
user1842744 Avatar asked Dec 04 '25 14:12

user1842744


1 Answers

If it is unique for user then how to save multiple regID's in server(dot net). Please give me some guidance.

When the device registered with the GCM server, the device MUST send that unique ID to your server, and then you save that value for sending messages.

How to send push notifications to multiple users using GCM?

You create message with a format. For multiple IDs, just fill the registration_ids key with your user IDs in the form of array object

Example in python:

ids=[]
query= // get all user record from database
for q in query:
    ids.append(q.registration_id)
// some code
jsonmessage=json.dumps({
    "registration_ids":ids,
    "data":{
        "message":message,
        "time":datetime.datetime.today().isoformat(),
        "sender":sender
     }
})
conn.send(jsonmessage)

That will look like this:

Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
  "registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...", "second_id", "third_id"],
  "data" : {
    ...
  },
}
like image 54
Zyoo Avatar answered Dec 07 '25 04:12

Zyoo