Reputation: 447
I have two methods for sending Push Notification First example:
public void SendPushNotification(String regId, String message, String googleAppId, String senderId)
{
var value = message;
var tRequest = WebRequest.Create(ConfigurationManager.AppSettings["RequestUrl"]);
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", googleAppId));
tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
string postData = "data.message=" + value + "®istration_id=" + regId + "";
var byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
var dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
var tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
if (dataStream != null)
{
var tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
var httpResponse = (HttpWebResponse) tResponse;
string statusCode = httpResponse.StatusCode.ToString();
tReader.Close();
}
if (dataStream != null) dataStream.Close();
tResponse.Close();
}
Second example. I use PushBroker from PushSharp
var push = new PushBroker();
push.RegisterGcmService(new GcmPushChannelSettings(apikey));
push.QueueNotification(
new GcmNotification().ForDeviceRegistrationId(deviceId).WithJson(json));
And this methods works good. I know how send batch push notification (i mean one message and song for a list of devices). I saw example there How to send batch notifications in GCM using PushSharp
But I would like to send push notification in batch, where for every device i have some special message and some song name. So did You know any solution for my problem?
Upvotes: 1
Views: 3052
Reputation: 393946
You can't send different messages to different Registration IDs in batch.
The JSON request that Google Cloud Messaging accepts supports a single payload (inside the data
element) and 1 to 1000 Registration IDs. That means in each request you can either send one message to one Registration ID or the same message to multiple Registration IDs.
Upvotes: 2