我执行此代码以使用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 …Run Code Online (Sandbox Code Playgroud) 我们的目标是从后端向设备组发送通知,并且只有从服务器端知道哪个设备应该接收通知。
我们已经对AppCenter进行了一些尝试,因为我们主要使用Xamarin iOS / Android / Forms,但是现在我们怀疑直接使用Firebase API可能会更好,因为它更广泛,功能更强大。
我看到使用新版本的API(HTTP V1)无法将通知发送到令牌列表,而使用registration_ids参数(https://firebase.google.com/docs/cloud-messaging / send-message)。
设备组名称(仅旧协议)
我无法使用主题,因为服务器在发送通讯时是为通知准备“邮件列表”的责任。
我当时在考虑使用设备组消息传递(https://firebase.google.com/docs/cloud-messaging/android/device-group),但是这些都是旧版api的一部分,我不确定是否有意义/可以在新版本的API中使用它们。
是否可以发送一批100-200-500推送通知,每个通知仅发送给一个令牌?从理论上讲,可以发送的通知没有限制,但是我担心发送过多的通知可能会被禁止。
使用旧版API更好吗?另外,AppCenter(Microsoft)也使用旧版API,这很明显是因为设置的工作方式,并且因为可以从AppCenter的控制台发送通知到令牌列表,而Firebase的控制台不提供此功能。
另一个人只是问了类似的问题,但答案是使用主题(如何一次为所有用户发送Firebase通知?)。
push-notification firebase firebase-cloud-messaging visual-studio-app-center