Azure通知集线器,使用模板向设备发送消息

时间:2016-11-22 17:11:39

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

我注册了一个包含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"]}

如上所示,一个模板包含变量消息,另一个消息消息

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

  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会发送所有模板的话?以及如何解决这个问题。

由于

1 个答案:

答案 0 :(得分:1)

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

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

outcome = await hub.SendTemplateNotificationAsync(properties, "chatTemplate");

谢谢,

Sateesh

相关问题