gpt4 book ai didi

android - 如何使用 GCM 向多个用户发送推送通知

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:21 24 4
gpt4 key购买 nike

我观看了一些演示,它在我的手机上运行良好。但我有一些问题。注册 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com