我使用 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 会发送所有模板,那么模板的用途是什么?以及如何解决这个问题。
谢谢
最佳答案
通知中心不会根据推送变量检测模板。您必须使用标签明确选择要发送的模板。例如,如果您想使用 ctemplate 发送通知(并且您已将此模板的标签定义为 chattemplate),那么您必须发出类似这样的发送命令。
var properties = new Dictionary<string, string>();
properties.Add("message", message);
properties.Add("conversation", "1234567890");
outcome = await hub.SendTemplateNotificationAsync(properties, "chatTemplate");
谢谢
萨提什
关于c# - Azure通知中心,使用模板向设备发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40747768/