Fer*_*tos 5 c# push-notification firebase firebase-cloud-messaging
我们已经在我们的应用程序中使用 Firebase 发送推送通知几个月了,我也在我的其他应用程序中使用了它。一切都很顺利,但是一周前我们开始收到重复的通知(并非总是如此)。奇怪的是,我们没有更改任何代码,它只是在 Android 和 iOS 中开始发生。它只是有时发生,并非总是发生,并且仅在某些用户/设备中发生。
我想知道是否有其他人正在使用 Firebase 经历这种情况。我认为这是一个 Firebase 错误,但我想看看是否有人可以确认相关内容。
ios 应用程序是用 swift 编写的,android 应用程序是用 Java 编写的。
顺便提一句。我们将基于此通过后端的 FCM 发送它。而且我们没有重复的主题。我检查过,设备只订阅一次。
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在后端发送通知的 C# 代码
public void sendPushNotification(string _title, string _message, string _topic, object customData = null)
{
var requestUri = "https://fcm.googleapis.com/fcm/send";
WebRequest webRequest = WebRequest.Create(requestUri);
webRequest.Method = "POST";
webRequest.Headers.Add(string.Format("Authorization: key={0}", FCM_SERVER_API_KEY));
webRequest.Headers.Add(string.Format("Sender: id={0}", FCM_SENDER_ID));
webRequest.ContentType = "application/json";
var data = new
{
to = "/topics/" + _topic, // this is for topic
notification = new
{
title = _title,
body = _message,
sound = "default"
},
data = customData, //custom data (got it from firebase documentation)
content_available = true
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
webRequest.ContentLength = byteArray.Length;
using (Stream dataStream = webRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse webResponse = webRequest.GetResponse())
{
using (Stream dataStreamResponse = webResponse.GetResponseStream())
{
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2330 次 |
最近记录: |