2017-01-17 56 views
0

我在我的android應用程序中使用FCM通知。 通知必須在同一時間使用.NET頁發送FCM通知到C#中的多個設備(但不是所有設備).net

public static void SendPushNotification() 
    { 

     try 
     { 

      string applicationID = "ABC****xyz"; 

      string senderId = "01*****89"; 

      string deviceId1 = "def****jdk"; 
      string deviceId2 = "lej****wka"; 
      string deviceId3 = "fqx****pls"; 

      WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); 
      tRequest.Method = "post"; 
      tRequest.ContentType = "application/json"; 
      var data = new 
      { 
       //This line is the problem 
       to = deviceId1+","+deviceId2+","+deviceId3, 
       notification = new 
       { 
        body = "Notification Body", 
        title = "Notification Title", 
        sound = "Enabled", 
        icon = "MyIcon" 

       } 
      }; 
      var serializer = new JavaScriptSerializer(); 
      var json = serializer.Serialize(data); 
      Byte[] byteArray = Encoding.UTF8.GetBytes(json); 
      tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); 
      tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); 
      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()) 
        { 
         using (StreamReader tReader = new StreamReader(dataStreamResponse)) 
         { 
          String sResponseFromServer = tReader.ReadToEnd(); 
          string str = sResponseFromServer; 
         } 
        } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      string str = ex.Message; 
     } 
    } 

線是問題是我連接多個設備發送到發送給用戶的數量有限(大約200個用戶) 如何才能發送這些設備的通知?

由於

回答

0

要發送推送通知到多個設備,則必須使用「registration_ids」而不是「到」包含設備令牌的陣列參數。限制是您可以通過此方法提供最多1000個設備令牌。查看此供參考FCM Downstream Messages

相關問題