Search code examples
c#androidpush-notificationgoogle-cloud-messagingpushsharp

How to send batch notifications in GCM using PushSharp


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


Solution

  • 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;
    }