2014-09-05 127 views
0

我正在使用Push Sharp Library向Android设备发送推送通知。是否有任何方法可以一次播出所有新闻?而不是将每条新闻分别发送给每个设备?与此相关的如何一次发送多个推送通知使用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也发生了变化。 在此先感谢...

+0

这可能有助于[使用PushSharp处理多个通知以用于ios和Android](http://stackoverflow.com/questions/17536259/processing-multiple-notifications-with-pushsharp-for-ios-and-android) – Enumy 2014-09-05 06:40:33

+0

否Hossam ..我已经经历了所有与此主题相关的讨论 – Avn 2014-09-05 06:42:01

+0

如果通知由于设备令牌已过期而失败,那么最好的方法是static void DeviceSubscriptionExpired(object sender,string expiredDeviceSubscriptionId,DateTime timestamp,INotification notification) Console.WriteLine(“Device Subscription Expired:”+ sender +“ - >”+ expiredDeviceSubscriptionId);}};}} \t \t} - 然后取消注册设备令牌。 – 2014-11-20 13:11:13

回答

0

这可能会帮助你

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(); 

    } 
+0

但您仍然需要在新闻上发送循环来发送每个通知的通知,但是无需使用注册ID进行通知 – 2014-11-16 18:25:14

0

1)你可以使用一个窗口服务和石英调度(触发按钮点击)来处理推送通知(如果我理解正确你的问题)

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

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

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