I am using Push Sharp Library to send push notifications to android devices. Is there any method to broadcast all news at a single shot? instead of sending each news to each device separately?
IList<Device> deviceList = new List<Device>();
IList<PushNotification> newsList = new List<PushNotification>();
deviceList = //method to fetch Device list
newsList = //method to fetch newsList
push.RegisterGcmService(new GcmPushChannelSettings("MY GCM KEY"));
foreach (Device device in deviceList)
{
if (device.DeviceType == "android")
{
foreach (PushNotification news in newsList)
{
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(device.PushToken).WithJson("{\"NewsTitle\":\"" + news.NewsTitle + "\"}"));
Thread.Sleep(5000);
}
}
}
Console.WriteLine("Waiting for Queue to Finish...");
//Stop and wait for the queues to drains
push.StopAllServices();
One more question related to this: My table storing registration IDs across device IDs is getting duplicate entries when the user re-installs the application. So the user getting same notification twice or thrice. How to resolve this? to keep the device Id as a primary key will do? But i have noticed, at times, the device ID is also getting changed after re-installation. Thanks in advance...