如何将firebase通知发送到多个主题

时间:2017-09-01 07:03:03

标签: c# firebase-cloud-messaging

我已经完成了以下单一主题发送工作的通知:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["FirebaseAPI"]);
client.DefaultRequestHeaders
                      .Accept
                      .Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header

client.DefaultRequestHeaders
                       .Authorization = new AuthenticationHeaderValue("key", "=" + ConfigurationManager.AppSettings["projectKey"]);

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "relativeAddress");
//How to Send more Id's loop it with the array

var data = new
{
    to = string.Concat("/topics/", 121),
    notification = new
    {
        body = "test",
        title = "FIRE alert"
    }
};

var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");//CONTENT-TYPE header

var resultArray = client.PostAsync("send", request.Content);
return resultArray.Result.Content.ReadAsStringAsync();

0 个答案:

没有答案