我执行此代码以使用FCM库将通知推送到移动设备
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; }
现在,如何向多设备发送消息,
假设字符串deviceid参数替换为List devicesIDs.
你能帮我吗
解决方法:
更新:对于v1,似乎不再支持registration_IDs.强烈建议使用主题. v1仅支持documentation中显示的参数.
只需在有效负载中使用registration_ids参数代替.根据您的使用情况,您可以使用Topic Messaging或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.
有关更多详细信息,请查看Sending to Multiple Devices in FCM文档.
总结以上是内存溢出为你收集整理的android – FCM(Firebase云消息传递)发送到多个设备全部内容,希望文章能够帮你解决android – FCM(Firebase云消息传递)发送到多个设备所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)