I'm using asp.net c# to send push notifications to users through GCM. This is my code to send notification.
string RegArr = string.Empty;
RegArr = string.Join("\",\"", RegistrationID); // (RegistrationID) is Array of endpoints
string message = "some test message";
string tickerText = "example test GCM";
string contentTitle = "content title GCM";
postData =
"{ \"registration_ids\": [ \"" + RegArr + "\" ], " +
"\"data\": {\"tickerText\":\"" + tickerText + "\", " +
"\"contentTitle\":\"" + contentTitle + "\", " +
"\"message\": \"" + message + "\"}}";
string response = SendGCMNotification("Api key", postData);
SendGCMNotification Function:-
private string SendGCMNotification(string apiKey, string postData, string postDataContentType = "application/json")
{
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// CREATE REQUEST
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
Request.Method = "POST";
Request.KeepAlive = false;
Request.ContentType = postDataContentType;
Request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
Request.ContentLength = byteArray.Length;
Stream dataStream = Request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//
// SEND MESSAGE
try
{
WebResponse Response = Request.GetResponse();
HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
{
var text = "Unauthorized - need new token";
}
else if (!ResponseCode.Equals(HttpStatusCode.OK))
{
var text = "Response from web service isn't OK";
}
StreamReader Reader = new StreamReader(Response.GetResponseStream());
string responseLine = Reader.ReadToEnd();
Reader.Close();
return responseLine;
}
catch (Exception ex)
{
throw ex;
}
return "error";
}
It is working properly and notification delivered properly to 1000 users.But now i have more then 1000 users and i have to send notifications to them all,but in gcm documentation it is specified that we can pass 1000 registrations ids at one time.what can i do to send notification to all user?Any help will be appriciated