0

As the title says, I have a list of all my registration IDs, and I want to send the same message to all of them at once.

I was told that GCM can handle approximately 1000 notifications at once, but I'm really confused as to how to do this in PushSharp (other than actually sending them individually, using a for loop). If anyone is familiar with this I would really appreciate some assistance.

He's some generic code

push.RegisterGcmService(new GcmPushChannelSettings(ApiKey));

push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(RegistrationID)
                                  .WithJson(json));

Instead of having 1 registration ID i'd like to send in a list of them. References to FAQ's but no actual answer on how to do so.

Reference 1

Reference 2

Reference 3

Eran
  • 387,369
  • 54
  • 702
  • 768
user2094139
  • 327
  • 8
  • 23

2 Answers2

3

I've never used Push Sharp, but based on this code :

You are currently using this method, which accepts a single Registration ID :

public static GcmNotification ForDeviceRegistrationId(this GcmNotification n, string deviceRegistrationId)
{
    n.RegistrationIds.Add(deviceRegistrationId);
    return n;
}

Use this method instead, which accepts multiple Registration IDs :

public static GcmNotification ForDeviceRegistrationId(this GcmNotification n, IEnumerable<string> deviceRegistrationIds)
{
    n.RegistrationIds.AddRange(deviceRegistrationIds);
    return n;
}
Eran
  • 387,369
  • 54
  • 702
  • 768
  • :) Thanks! I got it to work, I sent in a list of strings and it accepted it! – user2094139 Jul 30 '13 at 15:13
  • 1
    This methos send one message to batch devices. But how can I send batch notifications? Foe example: I have 20 different messages and 20 devices. How can I send push notification in batch ? – Oleh Jan 22 '14 at 13:06
0

You need to use that using to get extended methods

using PushSharp;
using PushSharp.Android;
using PushSharp.Core;

Then you can use

GcmNotification notification = new GcmNotification().ForDeviceRegistrationId(pRegistrationIds)
                                              .WithJson(pMessage);