i want to send notification to multiple device in single fcm request. my notification text is same for all devices.i have to send more then 10000 notification at same time to all user and text is same so i want to send all notification in minimum fcm request. I am using c# asmx service. hear is my code.
string regid="fcm_reg_id1,fcm_reg_id2" like this.
string applicationID = "abcd";
string SENDER_ID = "123456";
string regid="c_Z5yRoj4TY:APA91bGry2g_CIA1xaRy_LscxOvFX6YHqasKA96TjpG6yi1yytNyM5rtGL6DgxjGMSE5c74d7VdSL6W8zxO1ixVMlpVMwdgcrsGUWV0VfdbddC2XD","c_Z5yRoj4TY:APA91bGry2g_CIA1xaRy_LscxOvFX6YHqasKA96TjpG6yi1yytNyM5rtGL6DgxjGMSE5c74d7";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send");
httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
httpWebRequest.Method = "POST";
String collaps_key = "Score_update";
string json = "collapse_key=abcd" + "&data.header=cricket®istration_id=" + regId + "&data.notificationId=" + notificationId + "&data.message=" + msg;
httpWebRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
httpWebRequest.Headers.Add(string.Format("Sender: key={0}", SENDER_ID));
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
//Console.WriteLine(json);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
using (HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
retmsgid = result.ToString();
if (retmsgid.Trim() != "")
{
ResponceString = result.ToString();
string[] msgsplits = retmsgid.Split(',');
string[] msg1 = msgsplits[0].ToString().Split(':');
ReturnMessageId = msg1[1].ToString();
}
else
{
ReturnMessageId = "0";
}
}
httpResponse.Close();
httpResponse.Dispose();
httpWebRequest = null;
}
}
Since FCM does not allow specifying more than 1000 registration IDs when sending a message:
This parameter specifies a list of devices (registration tokens, or IDs) receiving a multicast message. It must contain at least 1 and at most 1000 registration tokens.
You only option is sending a message to a topic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With