Send template-notification to tile and toast once

600 views Asked by At

I register two different templates for my WindowsPhone clients (one for tile-update and one for toasts).

Is there a possibility to only send one notification and my WindowsPhone clients getting a toast notification and a tile update?

I found a forum thread on msdn with following message (in the answer):

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.

But that won't work for me. My client only gets the tile-update and not the toast notification.

I also tried a template with both in xml (tile and toast). Found here. But that also won't work (only toast visible on client).

I know, I can work with additional tags (like "toast" and "tile") and send the notifications like following code snippet. But I think this is an ugly solution:

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

Any help is appreciated. Thanks

Edit: My templates and my notification-properties:

Properties:

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

Tile-Template (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)
1

There are 1 answers

1
loop On BEST ANSWER
await hubClient.SendTemplateNotificationAsync(content, tags + " && toast");
await hubClient.SendTemplateNotificationAsync(content, tags + " && tile");

This is not an ugly solution, actually there is a reason behind it.Selection of

template/registration always based on tags not based on payload keys. so actually you've registered the templates to different set of tags like =>

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

In this case Device tile template is registered with tags : {"en-us", "tile"} and Toast is tags: {"en-us", "toast"} and these two registrations are different so you can't send them in single request.

IMO you can't have the both notification with this single call => SendTemplateNotificationAsync({“properties of template”}, “en-us”))' because again IMO(As I was not able to work it out some time before) Notification hub is not able to decide which template (tile, toast) he has to send to the device. because each of them is registered with different tags set as mentioned above.

Also Why it is not an ugly solution, because It gives you more control over your notifications because you know toast and tile notifications have different purpose, they simultaneously don't provide any extra value.

Tile notification => It is used for info that can last long for some time and does not stale sooner. Like counter, Back image, Some new update etc. also this info does not require instant user's attention immediately.

Toast Notification => It is used for sending out info that is quite instant(hope you understand what I mean).Like some new message came, you have released a new update etc.

If you send two notification simultaneously all the time then in that case It really does not add extra value.