简体   繁体   English

Google Cloud Messaging会向所有设备发送通知

[英]Google Cloud Messaging send notification to all devices

I'm new in GCM. 我是GCM的新手。 I would like to send an message to all devices that have the app installed. 我想向所有安装了该应用的设备发送消息。 I read about registration_id: after the first connection to GCM, google send this unique string to device. 我读到了registration_id:在第一次连接到GCM后,谷歌将这个唯一的字符串发送给设备。 I'm a beginner in server world but if I'm not mistaken, in server side, for sending a notification to devices I have to send array of registration_id and the message to google. 我是服务器世界的初学者,但如果我没有弄错,在服务器端,为了向设备发送通知,我必须发送registration_id数组和google的消息。

Google knows how has the registration id? 谷歌知道注册号码是怎么回事? Is there a way to send messages to all devices without pass the registrarions id? 有没有办法在没有通过注册号码的情况下向所有设备发送消息? Thank you. 谢谢。

With GCM 3.0 it's now possible to send a notification to all devices thanks to topics support. 使用GCM 3.0,现在可以通过主题支持向所有设备发送通知。 The app must suscribe to one or more topics and the server can send notifications to that topic without specifying individual devices. 应用程序必须包含一个或多个主题,服务器可以向该主题发送通知,而无需指定单个设备。

https://developers.google.com/cloud-messaging/topic-messaging https://developers.google.com/cloud-messaging/topic-messaging

You can suscribe all devices to a topic called "global" and then send the message to "/topics/global" instead of sending them to all the registration_ids. 您可以将所有设备设置为名为“global”的主题,然后将消息发送到“/ topics / global”,而不是将它们发送到所有registration_ids。

Is there a way to send messages to all devices without pass the registrarions id? 有没有办法在没有通过注册号码的情况下向所有设备发送消息?

No way. 没门。
After successfully registering on GCM, you (the Android application) should send the registration id to your application server and store them somewhere, in a database for example. 在GCM上成功注册后,您(Android应用程序)应将注册ID发送到您的应用程序服务器并将其存储在某个地方,例如数据库中。 This registration id will be used to send a notification to a particular device. 此注册ID将用于向特定设备发送通知。

To send a notification to all devices, would mean then to select all the registration ids from that database, and as you said, put them in an array and pass them further to GCM. 要向所有设备发送通知,则意味着从该数据库中选择所有注册ID,如您所述,将它们放入数组并将它们进一步传递给GCM。

Update: With Firebase Cloud Messaging, it is now possible to use https://firebase.google.com/docs/cloud-messaging/android/topic-messaging to send notifications without explicitly specifying registration IDs. 更新:借助Firebase云消息传递,现在可以使用https://firebase.google.com/docs/cloud-messaging/android/topic-messaging在不明确指定注册ID的情况下发送通知。

您需要发送设备的reg id列表,并且此列表不应超过1000这是GCM的限制,如果您要向1000多个设备发送消息,那么您需要以1000块的形式打破列表。

YES, there is a way to send a message to all! 是的,有办法向所有人发送消息!

Just send in the 'to' field the '/topics/global' value, rather then in the 'registration_ids' field the ids. 只需在'to'字段中输入'/ topics / global'值,而不是在'registration_ids'字段中输入id。

For example in php: 例如在php中:

'to' => "/topics/global",

and not this: 而不是这个:

'registration_ids'  => $this->devices

Create the notification_key , which identifies the device group by mapping a particular group to all of the group's associated registration tokens(You can create notification keys on the app server). 创建notification_key ,通过将特定组映射到该组的所有关联注册令牌来标识设备组(您可以在应用服务器上创建通知密钥)。 With a notification_key , instead of sending one message to one registration token at a time, the app server can send one message to the notification_key , and GCM then sends the message to all of the group's registration tokens. notification_key ,而不是在一次发送一个消息给一个登记令牌,该应用服务器可以发送一个消息给notification_key ,和GCM然后将该消息发送到所有的组的注册标记。

Also note that maximum number of members allowed for a notification_key is 20 . 另请注意,notification_key允许的最大成员数为20

Google Dev site has added a new guide for this topic in particular. Google Dev网站特别为此主题添加了新指南。 https://developers.google.com/cloud-messaging/notifications#sending_downstream_messages_to_device_group https://developers.google.com/cloud-messaging/notifications#sending_downstream_messages_to_device_group

I think there is a confusion here. 我觉得这里有一个混乱。 I had used the github sample code (app server in Java deployed to Tomcat for example) and Android app. 我曾使用github示例代码(例如,部署到Tomcat的Java中的app服务器)和Android应用程序。 There, I didn't "pass" or "send" any registration Id to the app server. 在那里,我没有“通过”或“发送”任何注册ID到应用服务器。 It called the relevant APIs to retrieve the registration IDs and use them to send notifications. 它调用相关API来检索注册ID并使用它们发送通知。 Why is every thread about GCM registration ID saying that one needs to pass registration IDs to 3rd party app server? 为什么每个关于GCM注册ID的帖子都说需要将注册ID传递给第三方应用服务器? I am afraid I don't agree. 我恐怕不同意。 I think 3rd Party app server can query GCM server itself to find out which devices have registered to receive notification from a particular sender (sender id). 我认为第三方应用服务器可以查询GCM服务器本身,以找出哪些设备已注册接收来自特定发件人的通知(发件人ID)。 Having to manually pass the registration IDs to 3rd party app server defeats the whole purpose of automating the process. 必须手动将注册ID传递给第三方应用服务器,才能实现自动化流程的全部目的。 Maybe I am missing something here or I am using the deprecated content. 也许我在这里遗漏了一些东西,或者我正在使用已弃用的内容。 Anyway, how can an automated process involve manual intervention once it starts? 无论如何,一旦启动,自动化流程如何才能涉及人工干预?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM