我正在构建一个 React Native 应用程序,并且我正在使用内置 c# 的服务器端应用程序在我的应用程序处于后台时向它发送通知。通知工作正常,但是当我添加声音参数时,自定义声音不起作用。我在 /res/raw
文件夹中添加了一个 sound.mp3 文件,并在我的负载中引用了该名称。知道我哪里出错了吗?提前致谢。
c# 代码
static void sendRequest(string fcmtoken, Dictionary<string, object> usdetails, string chatdocid,string userdocid,string reqtype,int time)
{
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
//serverKey - Key from Firebase cloud messaging server
tRequest.Headers.Add(string.Format("Authorization: key={0}", ""));
//Sender Id - From firebase project setting
tRequest.Headers.Add(string.Format("Sender: id={0}", ""));
tRequest.ContentType = "application/json";
var payload = new
{
to = fcmtoken,
priority = "high",
content_available = true,
notification = new
{
body = "You have a new chat request from " + usdetails["Name"].ToString(),
title = "New Chat Request",
badge = 1,
sound= "sound.mp3"
},
data = new
{
type = "chat",
chatdoc = chatdocid,
name = usdetails["Name"],
photo = usdetails["photopath"],
userdocid
}
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
//result.Response = sResponseFromServer;
}
}
}
}
}