2
votes

I am Using Azure Notification hub when sending push notifications to GCM and APN what I notice on the production it is only send to the first 10 registered devices and other new register device cant receive messages despite it is already registered on GCM . what i need is to send to all registered devices and they are round 600 devices.

public class Notifications { public static Notifications Instance = new Notifications();

    public NotificationHubClient Hub { get; set; }

    private Notifications()
    {
        string NotificationHubConnectionString = WebConfigurationManager.AppSettings["NotificationHubConnectionString"];

        string NotificationHubPath = WebConfigurationManager.AppSettings["NotificationHubPath"];

        Hub = NotificationHubClient.CreateClientFromConnectionString(NotificationHubConnectionString, NotificationHubPath, false);
    }



    public static async void SendNotificationAsync(string Message, string Type, string ID, string Date, string Summery, string Location, string Risk)
    {

        string to_tag = Type.Replace(" ", string.Empty);
        try
        {
            var notif = "{ \"data\" : {\"message\":\"" + Message + "\",\"type\":\"" + Type + "\",\"ID\":\"" + ID + "\",\"Date\":\"" + Date + "\",\"Summery\":\"" + Summery + "\",\"Risk\":\"" + Risk + "\",\"Location\":\"" + Location + "\"" + ", \"sound\" : \"default\"}}";
            var outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif);

            string msg = string.Format("This Notification: " + Message + " has been delivered to this number [" + outcome.Success.ToString() + "] of android Mobiles");
            Logger.LogMessage(msg, EventLogEntryType.Information);
        }
        catch (Exception ex)
        {
            string msg = string.Format("Coudn't send notification to android mobiles");
            Logger.LogMessage(msg, EventLogEntryType.Error);
            Logger.LogException(ex, EventLogEntryType.Error);

        }
        try
        {
            var alert = "{\"aps\":{\"alert\":\"" + Message + "\",\"type\":\"" + Type + "\",\"ID\":\"" + ID + "\",\"Date\":\"" + Date + "\",\"Summery\":\"" + Summery + "\",\"Risk\":\"" + Risk + "\",\"location\":\"" + Location + "\" " + ", \"sound\" : \"default\"}}";

            var outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, to_tag);
            string msg = string.Format("This Notification: " + Message + " has been delivered to this number ["+ outcome.Success.ToString() +"] of IOS Mobiles");
            Logger.LogMessage(msg, EventLogEntryType.Information);
        }
        catch (Exception ex)
        {
            string msg = string.Format("Coudn't send notification to IOS mobiles");
            Logger.LogMessage(msg, EventLogEntryType.Error);
            Logger.LogException(ex, EventLogEntryType.Error);

        }

    }
1

1 Answers

2
votes

I am assuming you are using the built-in testing tool in the Notification Hubs blade in the Azure Portal or Visual Studio.

This is by design - a test notification from there will go to 10 random devices. You will need to have a real backend sending notifications in order to propagate to all devices that are registered.

Details are outlined here.

Note that the use of this property is heavily throttled and so you must only use this in dev/test environment with limited set of registrations. We only send debug notifications to 10 devices. We also have a limit of processing debug sends to be 10 per minute.

Check for this line:

bool enableTestSend = true;
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connString, hubName, enableTestSend);

In order to deliver for more than 10 devices, you need to make sure that you are not using EnableTestSend.