【问题标题】:How to send multiple Push notifications at a time Using Push sharp library for Android?如何使用适用于 Android 的 Push sharp 库一次发送多个推送通知?
【发布时间】: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


【解决方案1】:

这可能对你有帮助

private void PushGCM(List<string> registerationIds)
    {
        var push = new PushBroker();

        push.RegisterGcmService(new GcmPushChannelSettings("applicationID"));

        GcmNotification gcmNotifiction = new GcmNotification();
        gcmNotifiction.RegistrationIds.AddRange(registerationIds);
        gcmNotifiction.WithJson(@"{""alert"":""Hello World!"",""badge"":7,""sound"":""sound.caf""}");

        //Stop and wait for the queues to drains
        push.StopAllServices();

    }

【讨论】:

  • 但您仍然需要在新闻上循环以发送每个通知,但无需使用注册 ID 进行此操作
【解决方案2】:

1) 您可以使用 Windows 服务和石英调度程序(在按钮单击时触发)来处理推送通知(如果我正确理解了您的问题!)

石英参考以下内容:
http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/index.html

2)关于重复条目,我认为您应该使用新令牌(与 deviceid 匹配)更新现有设备,而不添加新令牌或使旧令牌无效。

而且,我认为设备 ID 不会在每次重新安装期间发生变化。只有设备令牌(注册 id)发生变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多