locked
Send both Toast and Tile Notification simultaneously using Template feature of Notification Hub RRS feed

  • Question

  • Hi, I am using WNS(Windows Notification Service) With Notification Hub to send Push Notifications to my WP 8.1 Application. I am basically sending localized notification using Template feature of Notification Hub. I have used Localized News example  reference for sending localized used.

    Here are my templates and how I am registering them, also How my Dictionary payloads look like :-

    Toast Template Method :- 

    public static string GetToastText01Template(string param,string line1)
            {
                return string.Format(@"<toast launch=""$({0})"">
                                    <visual>
                                        <binding template=""ToastText01"">
                                            <text id=""1"">$({1})</text>
                                        </binding>
                                    </visual>
                                </toast>", param, line1);
            }

    Tile Template Method :-

    public static string CreateSquare150_150BackgroundTextTemplateWns(string backText)
            {
                return string.Format(@"<tile>
                                          <visual >
                                              <binding template=""TileSquarePeekImageAndText01"">
                                                 <image id=""1"" src=""ms-appx:///ApplicationIcon_173_173.png"" alt=""alt text"" />
                                                <text id=""1"">$({0})</text>
                                              </binding>
                                          </visual>
                                     </tile>", backText);
            }

    Registration With Notificaiton Hub (Part of Register Method basically) :-

    var toasttemplate = GetToastText01Template("NavigateToPageUri" ,GetToastCultureKey(culture));
     await _hubClient.CreateWindowsTemplateRegistrationAsync(ChannelUri, toasttemplate, tags);


    var tileTemplate = ToastFactory.CreateSquare150_150BackgroundTextTemplateWns(GetTileBackTextCultureKey(culture));
    await _hubClient.CreateWindowsTemplateRegistrationAsync(ChannelUri, tileTemplate, tags)

    Toast payload In terms of Dictionary :- 

    Tile Payload Dictionary :-

    Note :- I have ensured that Keys for both the templates must be different during registering the templates so that both templates doesn't mix with each other. 

    Problem :- When I am registering only one Template, doesn't matter Whether it is Toast or Tile, I am able to get the notification on my app successfully(Both of Toast and Tile ,individually, working fine). But When I register both of the Templates simultaneously or Individually, then none on them is working.

    Questions :- 

    1) Can you let me know how basically Notification Hub select the Template from Payload Dictionary ? Like in case of two different registered templates.

    2) How can we send Two localized Notifications simultaneously using Template feature of Notification Hub?



    Monday, February 2, 2015 11:05 AM

Answers

  • Hi Tanuj,
    Selection of template/registration always based on tags not based on payload keys.

    Just to explain, you have following two devices.
    device A - toast template,  tags: {"en-us", "toast"}
    device A - tile template , tags : {"en-us", "tile"}
    device B - toast template,  tags: {"en-fr", "toast"}
    device B - tile template , tags : {"en-fr", "tile"}

    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 if you just want to send the toast notification to device A, you have to call something like this,
    SendTemplateNotificationAsync({“properties of template”}, “en-us && toast”)). FYI Second parameter is a tag expression: Please refer following link to know more about tag expressions:
    https://msdn.microsoft.com/en-us/library/azure/dn530749.aspx

    To answer your second question, register template with language tag along with other tags (just like above example). Then when you are sending notification, include that tag in your tag expression.
    Example: SendTemplateNotificationAsync({“properties of template”}, “en-us && toast”)), this one send toast notifications to all “en-us” local devices.

    Thanks,
    Sateesh


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Monday, February 2, 2015 7:01 PM