1

我正在使用Azure通知中心,并且我想向.NET后端中的所有注册设备发送推送通知消息。但我不确定这种方式会发送到所有设备,因为我没有办法检查收到推送消息的设备数量。 那么,怎么样,我可以发送推送消息给所有设备,或者可以确保这种方式是正确的?使用.NET向Azure通知中心的所有注册设备发送推送通知

public static async Task<bool> SendBroadcast(string msg) 
    { 
     try 
     { 
      var notificationHubClient = NotificationHubClient.CreateClientFromConnectionString(ConfigurationManager.AppSettings["ServiceBusPushNotificationConnectionString"], ConfigurationManager.AppSettings["ServiceBusPushNotificationName"]); 
      Dictionary<string, string> param = new Dictionary<string, string>(); 
      param.Add("message", msg); 
      param.Add("alert", msg); 
      var template = new TemplateNotification(param); 
      var result = await notificationHubClient.SendNotificationAsync(template); 
      Console.WriteLine(JsonConvert.SerializeObject(result)); 
      return true; 
     } 
     catch (Exception exception) 
     { 
      Console.WriteLine(exception.Message); 
      return false; 
     } 
    } 
+0

小记,'result'是具有支撑型'NotificationOutcome'的'Failure'和道具'Success'类型都是长。所以你回归真实,虽然它可能是错误的(失败)? –

回答

0

您需要使用的标签,在Routing and Tag Expressions描述:

针对特定注册的唯一方法是将它们与 标签关联,然后再指定标签。如注册 管理中所述,为了接收推送通知,应用程序必须在注册通知中心上注册设备句柄 。在通知集线器上创建的注册为 后,应用程序后端可以向其发送推送 通知。该应用程序后端可以选择 注册在以下 方式与特定的通知目标:

  1. 广播:通知中心所有注册接收 通知。

  2. 标签:包含指定标签的所有注册都会收到 通知。

  3. 标签表达:其标签集合与 指定表达式匹配的所有注册都会收到通知。

注意,there're limitations on broadcast messages,你需要考虑到。请参阅Breaking News App Sample关于如何使用广播通知的详细信息。