如何向特定的Notification Hub安装模板发送通知?

时间:2017-05-26 15:53:36

标签: c# .net azure azure-notificationhub

我正在从我的.NET后端服务器代码注册安装,每个代码都有多个模板。例如:

var installation = new Installation
{
    InstallationId = id,
    PushChannel = token,
    Templates = new Dictionary<string, InstallationTemplate>(),
    Tags = new List<string> { "userId:123456" },
    Platform = NotificationPlatform.Gcm
};

installation.Templates.Add("template1", new InstallationTemplate { Body = "{\"data\":{\"message\":\"$(message)\"}}"});
installation.Templates.Add("template2", new InstallationTemplate { Body = "{\"data\":{\"message2\":\"$(message)\"}}"});

await _client.CreateOrUpdateInstallationAsync(installation);

如何在发送通知时定位特定模板?我在SDK中看到的全部内容如下:

await _client.SendTemplateNotificationAsync(
    new Dictionary<string, string>
    {
        { "message",  "Hello world." }
    }, "userId:123456");

SendTemplateNotificationAsync方法没有任何参数可让我指定我定位的模板(例如template2)。

将使用哪个模板?我在这里误解了什么吗?

1 个答案:

答案 0 :(得分:2)

InstallationTemplate class具有Tags属性。这是区分模板的一种方法。

在您的情况下,看起来您可以跳过通过Installation.Tags属性标记整个安装,并通过userId:123456-template在特定模板上使用InstallationTemplate.Tags标记之类的内容。然后以与您相同的方式调用SendTemplateNotificationAsync,但使用模板后缀。

相关问题