【发布时间】:2014-09-05 06:32:50
【问题描述】:
我正在使用 Push Sharp 库向 Android 设备发送推送通知。有什么方法可以一次播放所有新闻吗?而不是将每个新闻分别发送到每个设备?
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();
与此相关的另一个问题:当用户重新安装应用程序时,我的跨设备 ID 存储注册 ID 的表会出现重复条目。因此,用户两次或三次收到相同的通知。如何解决这个问题?保持设备ID作为主键会怎样?但我注意到,有时,重新安装后设备 ID 也会发生变化。 提前谢谢...
【问题讨论】:
-
No Hossam.. 我已经完成了与此主题相关的所有讨论
-
如果通知失败,最好的方法是设备令牌已过期 static void DeviceSubscriptionExpired(object sender, string expiredDeviceSubscriptionId, DateTime timestamp, INotification notification) { Console.WriteLine("Device Subscription Expired: " + 发件人 + " -> " + expiredDeviceSubscriptionId); } - 然后注销设备令牌。
标签: c# android asp.net push-notification pushsharp