将模板通知发送到 tile 和 toast 一次

Send template-notification to tile and toast once

我为我的 WindowsPhone 客户端注册了两个不同的模板(一个用于 tile-update,一个用于 toasts)。

是否有可能只发送一个通知,我的 WindowsPhone 客户端就会收到 toast 通知和磁贴更新?

我发现 forum thread on msdn 包含以下消息(在答案中):

If you call a method SendTemplateNotificationAsync({“properties of template”}, “en-us”)) like this, That will target the toast and tile both notifications to the device A.

但这对我不起作用。我的客户只收到 tile-update 而不是 toast 通知。

我还在 xml(磁贴和吐司)中尝试了一个模板。 Found here。但这也行不通(仅在客户端可见 toast)。

我知道,我可以使用额外的标签(如 "toast" 和 "tile")并像下面的代码片段一样发送通知。但我认为这是一个丑陋的解决方案:

await hubClient.SendTemplateNotificationAsync(content, tags + " && toast");
await hubClient.SendTemplateNotificationAsync(content, tags + " && tile");

感谢任何帮助。谢谢

编辑:我的模板和通知属性:

属性:

var content = new Dictionary<string, string>
{
    {"title_en", "English title"},
    {"message_en", "English content"},
    {"title_de", "Deutscher Titel"},
    {"message_de", "Deutscher Inhalt"},
    {"url", url},
    {"count", count.ToString()}
};

Toast 模板 (WindowsPhone)

String.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<wp:Notification xmlns:wp=\"WPNotification\">" +
    "<wp:Toast>" +
    "<wp:Text1>$(title_{0})</wp:Text1>" +
    "<wp:Text2>$(message_{0})</wp:Text2>" +
    "<wp:Param>$(url)</wp:Param>" +
    "</wp:Toast>" +
    "</wp:Notification>", language);

磁贴模板 (WindowsPhone)

String.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<wp:Notification xmlns:wp=\"WPNotification\">" +
    "<wp:Tile Template=\"IconicTile\">" +
    "<wp:SmallIconImage>Small.png</wp:SmallIconImage>" +
    "<wp:IconImage>Large.png</wp:IconImage>" +
    "<wp:WideContent1>$(title_{0})</wp:WideContent1>" +
    "<wp:WideContent2>$(message_{0})</wp:WideContent2>" +
    "<wp:WideContent3 Action=\"Clear\"></wp:WideContent3>" +
    "<wp:Count>$(count)</wp:Count>" +
    "<wp:Title>AppName</wp:Title>" +
    "</wp:Tile>" +
    "</wp:Notification>", language)
await hubClient.SendTemplateNotificationAsync(content, tags + " && toast");
await hubClient.SendTemplateNotificationAsync(content, tags + " && tile");

这不是一个丑陋的解决方案,实际上

的 it.Selection 背后是有原因的

template/registration always based on tags not based on payload keys. 所以实际上您已经将模板注册到不同的标签集,例如 =>

device A - toast template,  tags: {"en-us", "toast"}
device A - tile template , tags : {"en-us", "tile"}

在这种情况下,设备磁贴模板是用 tags : {"en-us", "tile"} 注册的,Toast 是 tags: {"en-us", "toast"},这两个注册是不同的,因此您不能在单个请求中发送它们。

IMO you can't have the both notification with this single call => SendTemplateNotificationAsync({“properties of template”}, “en-us”))' 因为 IMO(因为我之前没能解决)通知中心无法决定他使用哪个模板(tile,toast)必须发送到设备。因为他们每个人都注册了不同的标签集,如上所述。

另外为什么它不是一个丑陋的解决方案,因为它让您可以更好地控制您的通知,因为您知道 toast 和磁贴通知有不同的目的,它们同时不提供任何额外的价值。

平铺通知 => 它用于可以持续一段时间并且不会很快过时的信息。像计数器、背面图像、一些新的更新等,这些信息也不需要立即引起用户的注意。

Toast Notification => 用于发送非常即时的信息(希望你明白我的意思)。就像有新消息来了,你发布了一个新消息更新等

如果你一直同时发送两个通知那么在那种情况下它真的没有增加额外的价值。