如何向特定的通知中心安装模板发送通知?

How do you send a notification to a specific Notification Hub installation template?

我正在从我的 .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)。

将使用哪个模板?我是不是误会了什么?

InstallationTemplate classTags 属性。这是区分模板的一种方式。

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