【问题标题】:Azure notification Hub, sending message to device using templateAzure 通知中心,使用模板向设备发送消息
【发布时间】:2016-11-22 17:11:39
【问题描述】:

我用 2 个模板注册了一个设备

    {
"handle":"handleIdGoeshere",
"installationId":"installationIdgoeshere",
"platform":"gcm",
"templates":{
    "ctemplate": 
    {
       "Body" : "{\"data\": {\"message\": \"$(message)\",\"conversation\":    \"$(conversation)\"}}",
    "Tags":["chatTemplate"]
    },
    "rtemplate": 
    {
    "Body" : "{\"data\": {\"message\": \"$(message)\"}}",
    "Tags":["regularTemplate"]
    }
    },"tags":["device:tablet","language:en"]}

正如您在上面看到的,一个模板有变量message,另一个有messageconversation

每个模板都有一个指定的名称,但是在发送推送时

  var properties = new Dictionary<string, string>();
                properties.Add("message", message);
                properties.Add("conversation", "1234567890");

                outcome = await hub.SendTemplateNotificationAsync(properties);

我无法指定我想使用哪个模板,我认为 azure 会根据用于推送的变量自动检测模板,但我猜不是这样,如果我发送推送时只设置了消息变量我得到以下内容

{
 conversation=, 
 message=another test
}

这会导致解析错误,因为对话变量为空白。那么如果 azure 会发送所有模板,那么模板的目的是什么?以及如何解决这个问题。

谢谢

【问题讨论】:

    标签: c# azure push-notification azure-notificationhub


    【解决方案1】:

    Notification Hub 不会根据推送变量检测模板。您必须使用标签明确选择要发送的模板。例如,如果您想使用 ctemplate 发送通知(并且您已将此模板的标签定义为 chattemplate),那么您必须发出类似这样的发送命令。

    var properties = new Dictionary<string, string>();
    properties.Add("message", message);
    properties.Add("conversation", "1234567890");
    
    outcome = await hub.SendTemplateNotificationAsync(properties, "chatTemplate");
    

    谢谢,

    萨蒂什

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 2017-08-25
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 2014-07-23
      相关资源
      最近更新 更多