MS Azure仅向10台设备发送通知

时间:2016-02-19 21:05:12

标签: azure push-notification google-cloud-messaging azure-notificationhub

我在向GCM和APN发送推送通知时使用Azure通知中心我在生产中注意到它只发送到前10个注册设备,而其他新注册设备无法接收消息,尽管它已经在GCM上注册。我需要的是发送到所有注册的设备,他们是圆600设备。

公共类通知     {         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 个答案:

答案 0 :(得分:2)

我假设您正在使用Azure门户或Visual Studio中的Notification Hub刀片中的内置测试工具。

这是设计 - 来自那里的测试通知将转到10个随机设备。您需要有一个真实的后端发送通知,以便传播到所有已注册的设备。

概述了here

  

请注意,此属性的使用受到严重限制,因此您   必须只在具有有限集合的开发/测试环境中使用它   注册。我们只向10台设备发送调试通知。我们也   处理调试发送的限制为每分钟10次。

检查此行:

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

为了提供超过10台设备,您需要确保没有使用EnableTestSend