简体   繁体   English

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

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

I am registering installations from my .NET backend server code with multiple templates each. 我正在从.NET后端服务器代码中注册安装,每个版本都有多个模板。 For example: 例如:

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);

How do I target a specific template when sending a notification? 发送通知时如何定位特定模板? All I see in the SDK is the following: 我在SDK中看到的只是以下内容:

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

The SendTemplateNotificationAsync method does not have any parameters that let me specify which template I am targeting (for example, template2 ). SendTemplateNotificationAsync方法没有任何参数可以让我指定我要定位的模板(例如template2 )。

Which template will be used? 将使用哪个模板? Am I misunderstanding something here? 我在这里误会什么吗?

InstallationTemplate class has Tags property. InstallationTemplate类具有Tags属性。 That's a way to differentiate between templates. 这是区分模板的一种方法。

In your case, it looks like you could just skip tagging the entire installation via Installation.Tags property and use something like userId:123456-template tag on specific templates through InstallationTemplate.Tags . 在你的情况下,它看起来像你可以直接跳过标记通过整个安装Installation.Tags属性,并使用类似userId:123456-template通过标签上的特定模板InstallationTemplate.Tags Then invoke SendTemplateNotificationAsync the same way you do, but with the template suffix. 然后以与您相同的方式调用SendTemplateNotificationAsync ,但使用模板后缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM