我想同时将不同的有效负载推送到不同的设备。现在我只能使用下面的代码将相同的有效负载推送到不同的设备。
string stringregIds = null;
List<string> regIDs = new List<string>();
//Add some regID into the list
stringregIds = string.Join("\",\"", regIDs.ToArray());;
string applicationID = "appID";
string SENDER_ID = "senderID";
string value = "Hello";
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/json;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
string postData = "{\"collapse_key\":\"score_update\",\"time_to_live\":108,\"delay_while_idle\":true,\"data\": { \"message\" : "
+"\""+value+"\",\"time\": "+"\""+System.DateTime.Now.ToString()+"\"},\"registration_ids\":[\""+stringregIds+"\"]}";
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
是否有任何解决方案可以将多个有效负载发送到多个设备?
答案 0 :(得分:0)
没有将不同有效负载发送到不同设备的快捷方式。您必须在单独的HTTP请求中发送每条消息。每个请求都将包含一个注册ID。