• <small id='JxhRr'></small><noframes id='JxhRr'>

        <tfoot id='JxhRr'></tfoot>
          <bdo id='JxhRr'></bdo><ul id='JxhRr'></ul>
        <i id='JxhRr'><tr id='JxhRr'><dt id='JxhRr'><q id='JxhRr'><span id='JxhRr'><b id='JxhRr'><form id='JxhRr'><ins id='JxhRr'></ins><ul id='JxhRr'></ul><sub id='JxhRr'></sub></form><legend id='JxhRr'></legend><bdo id='JxhRr'><pre id='JxhRr'><center id='JxhRr'></center></pre></bdo></b><th id='JxhRr'></th></span></q></dt></tr></i><div id='JxhRr'><tfoot id='JxhRr'></tfoot><dl id='JxhRr'><fieldset id='JxhRr'></fieldset></dl></div>
        <legend id='JxhRr'><style id='JxhRr'><dir id='JxhRr'><q id='JxhRr'></q></dir></style></legend>
      1. FCM(Firebase 云消息传递)发送到多个设备

        FCM (Firebase Cloud Messaging) Send to multiple devices(FCM(Firebase 云消息传递)发送到多个设备)

            <tbody id='u08Bs'></tbody>
          <tfoot id='u08Bs'></tfoot>
            <bdo id='u08Bs'></bdo><ul id='u08Bs'></ul>

            1. <legend id='u08Bs'><style id='u08Bs'><dir id='u08Bs'><q id='u08Bs'></q></dir></style></legend>
              <i id='u08Bs'><tr id='u08Bs'><dt id='u08Bs'><q id='u08Bs'><span id='u08Bs'><b id='u08Bs'><form id='u08Bs'><ins id='u08Bs'></ins><ul id='u08Bs'></ul><sub id='u08Bs'></sub></form><legend id='u08Bs'></legend><bdo id='u08Bs'><pre id='u08Bs'><center id='u08Bs'></center></pre></bdo></b><th id='u08Bs'></th></span></q></dt></tr></i><div id='u08Bs'><tfoot id='u08Bs'></tfoot><dl id='u08Bs'><fieldset id='u08Bs'></fieldset></dl></div>
              • <small id='u08Bs'></small><noframes id='u08Bs'>

                1. 本文介绍了FCM(Firebase 云消息传递)发送到多个设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我执行此代码以使用 FCM 库将通知推送到移动设备

                  public string PushFCMNotification(string deviceId, string message){字符串 SERVER_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxx";var SENDER_ID = "xxxxxxxxx";变量值 = 消息;WebRequest tRequest;tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");tRequest.Method = "发布";tRequest.ContentType = "应用程序/json";tRequest.Headers.Add(string.Format("授权:key={0}", SERVER_API_KEY));tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));var 数据 = 新{至 = 设备 ID,通知=新{body = "这是消息",title = "这是标题",图标 = 我的图标"}};var serializer = new JavaScriptSerializer();var json = serializer.Serialize(data);Byte[] byteArray = Encoding.UTF8.GetBytes(json);tRequest.ContentLength = byteArray.Length;流数据流 = tRequest.GetRequestStream();dataStream.Write(byteArray, 0, byteArray.Length);数据流.关闭();WebResponse tResponse = tRequest.GetResponse();数据流 = tResponse.GetResponseStream();StreamReader tReader = new StreamReader(dataStream);字符串 sResponseFromServer = tReader.ReadToEnd();tReader.Close();数据流.关闭();tResponse.Close();返回 sResponseFromServer;}

                  现在,如何向多台设备发送消息,假设字符串 deviceId 参数替换为 List devicesIDs.

                  你能帮忙吗

                  解决方案

                  更新:v1似乎不再支持registration_ids.强烈建议改用主题.v1 仅支持 文档 中显示的参数.


                  只需使用 registration_ids 参数而不是有效负载中的 to.同样根据您的用例,您可以使用 主题消息传递或设备组消息传递.

                  <块引用>

                  主题消息传递

                  Firebase 云消息传递 (FCM) 主题消息传递允许您向已选择加入特定主题的多个设备发送消息.基于发布/订阅模型,主题消息支持每个应用程序的无限订阅.您可以根据需要编写主题消息,Firebase 会处理消息路由并将消息可靠地传递到正确的设备.

                  例如,本地天气预报应用程序的用户可以选择加入恶劣天气警报".主题并接收风暴威胁指定区域的通知.体育应用程序的用户可以订阅他们最喜欢的球队的实时比赛比分的自动更新.开发者可以选择任何匹配正则表达式的主题名称:"/topics/[a-zA-Z0-9-_.~%]+".


                  <块引用>

                  设备组消息

                  通过设备群组消息传递,应用服务器可以将单个消息发送到在属于某个群组的设备上运行的应用的多个实例.通常是组";指属于单个用户的一组不同设备.组中的所有设备共享一个公共通知密钥,这是 FCM 用来将消息扇出到组中所有设备的令牌.

                  设备群组消息让群组中的每个应用实例都可以反映最新的消息状态.除了向下游发送消息到通知键之外,您还可以使设备能够向设备组发送上游消息.您可以将设备组消息与 XMPP 或 HTTP 连接服务器一起使用.发送到 iOS 设备时数据负载限制为 2KB,其他平台为 4KB.

                  notification_key 允许的最大成员数为 20.


                  有关更多详细信息,您可以查看 发送到多个设备FCM 文档.

                  I execute this code to push notifications to mobile device using FCM library

                  public string PushFCMNotification(string deviceId, string message) 
                      {
                          string SERVER_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxx";
                          var SENDER_ID = "xxxxxxxxx";
                          var value = message;
                          WebRequest tRequest;
                          tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                          tRequest.Method = "post";
                          tRequest.ContentType = "application/json";
                          tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));
                  
                          tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
                  
                          var data = new
                          {
                              to = deviceId,
                              notification = new
                              {
                                  body = "This is the message",
                                  title = "This is the title",
                                  icon = "myicon"
                              }
                          };
                  
                          var serializer = new JavaScriptSerializer();
                          var json = serializer.Serialize(data);
                  
                          Byte[] byteArray = Encoding.UTF8.GetBytes(json);
                  
                          tRequest.ContentLength = byteArray.Length;
                  
                          Stream dataStream = tRequest.GetRequestStream();
                          dataStream.Write(byteArray, 0, byteArray.Length);
                          dataStream.Close();
                  
                          WebResponse tResponse = tRequest.GetResponse();
                  
                          dataStream = tResponse.GetResponseStream();
                  
                          StreamReader tReader = new StreamReader(dataStream);
                  
                          String sResponseFromServer = tReader.ReadToEnd();
                  
                  
                          tReader.Close();
                          dataStream.Close();
                          tResponse.Close();
                          return sResponseFromServer;
                      }
                  

                  now, how to send message to multi device, assume that string deviceId parameter replaced with List devicesIDs.

                  can you help

                  解决方案

                  Update: For v1, it seems that registration_ids is no longer supported. It is strongly suggested that topics be used instead. Only the parameters shown in the documentation are supported for v1.


                  Simply use the registration_ids parameter instead of to in your payload. Depending also on your use case, you may use either Topic Messaging or Device Group Messaging.

                  Topic Messaging

                  Firebase Cloud Messaging (FCM) topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. Based on the publish/subscribe model, topic messaging supports unlimited subscriptions for each app. You compose topic messages as needed, and Firebase handles message routing and delivering the message reliably to the right devices.

                  For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams. Developers can choose any topic name that matches the regular expression: "/topics/[a-zA-Z0-9-_.~%]+".


                  Device Group Messaging

                  With device group messaging, app servers can send a single message to multiple instances of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user. All devices in a group share a common notification key, which is the token that FCM uses to fan out messages to all devices in the group.

                  Device group messaging makes it possible for every app instance in a group to reflect the latest messaging state. In addition to sending messages downstream to a notification key, you can enable devices to send upstream messages to a device group. You can use device group messaging with either the XMPP or HTTP connection server. The limit on data payload is 2KB when sending to iOS devices, and 4KB for other platforms.

                  The maximum number of members allowed for a notification_key is 20.


                  For more details, you can check out the Sending to Multiple Devices in FCM docs.

                  这篇关于FCM(Firebase 云消息传递)发送到多个设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding headers in ASP.NET MVC 3(在 ASP.NET MVC 3 中添加标头)
                  Response.Redirect strips Header Referrer - Possible to Add it Back?(Response.Redirect 剥离 Header Referrer - 可以将其添加回来吗?)
                  Faking browser request in ASP.net C#(在 ASP.net C# 中伪造浏览器请求)
                  How to delete IIS custom headers like X-Powered-By: ASP.NET from response?(如何从响应中删除 IIS 自定义标头,例如 X-Powered-By: ASP.NET?)
                  What does vary:accept-encoding mean?(变化:接受编码是什么意思?)
                  Cache-control: no-store, must-revalidate not sent to client browser in IIS7 + ASP.NET MVC(缓存控制:在 IIS7 + ASP.NET MVC 中,没有存储、必须重新验证未发送到客户端浏览器)

                        <tbody id='rXVNL'></tbody>
                      <i id='rXVNL'><tr id='rXVNL'><dt id='rXVNL'><q id='rXVNL'><span id='rXVNL'><b id='rXVNL'><form id='rXVNL'><ins id='rXVNL'></ins><ul id='rXVNL'></ul><sub id='rXVNL'></sub></form><legend id='rXVNL'></legend><bdo id='rXVNL'><pre id='rXVNL'><center id='rXVNL'></center></pre></bdo></b><th id='rXVNL'></th></span></q></dt></tr></i><div id='rXVNL'><tfoot id='rXVNL'></tfoot><dl id='rXVNL'><fieldset id='rXVNL'></fieldset></dl></div>

                      <small id='rXVNL'></small><noframes id='rXVNL'>

                      <tfoot id='rXVNL'></tfoot>

                          <bdo id='rXVNL'></bdo><ul id='rXVNL'></ul>
                        • <legend id='rXVNL'><style id='rXVNL'><dir id='rXVNL'><q id='rXVNL'></q></dir></style></legend>