我观看了一些演示,它在我的手机上运行良好。但我有一些问题。注册 ID 对于应用程序或用户来说是唯一的吗?如果它对用户来说是唯一的,那么如何在服务器(点网)中保存多个 regID。请给我一些指导。
最佳答案
If it is unique for user then how to save multiple regID's in server(dot net). Please give me some guidance.
当设备向 GCM 服务器注册时,设备必须将该唯一 ID 发送到您的服务器,然后您保存该值以用于发送消息。
How to send push notifications to multiple users using GCM?
您创建具有格式的消息。对于多个ID,只需将您的用户ID以数组对象的形式填入registration_ids
键
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)
看起来像这样:
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
"registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...", "second_id", "third_id"],
"data" : {
...
},
}
关于android - 如何使用 GCM 向多个用户发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14229379/