Search code examples
windows-phone-8push-notificationazure-notificationhub

How to send a tile push notification for WP8 from Azure notification hub and C# application?


I am trying to send a tile notification to my WP8 app using a C# Winforms app that has Azure service bus functionality. I have set up the app with the channels needed and have successfully been able to send toast notifications to the app. However, tile notifications have proven to be more difficult. I have been attempting to send them the same way using XML but I am unsure why it is not working on my app. I have the app using channel.BindToShellTile(); along with the other channel logic but I do not think the problem is there as I am able to receive toasts along that same channel. I am currently trying to send this:

string tile = "<?xml version=\"1.0\"?>" +
            "<wp:Notification xmlns:wp=\"WPNotification\" Version=\"2.0\">" +
                "<wp:Tile Template=\"FlipTile\">" +
                    "<wp:BackgroundImage Action=\"Clear\">" + "red.png" + "</wp:BackgroundImage>" +
                    "<wp:Count Action=\"Clear\">" + "1" + "</wp:Count>" +
                    "<wp:Title Action=\"Clear\">" + "SENDPUSH" + "</wp:Title>" +
                    "<wp:BackBackgroundImage Action=\"Clear\">" + "blue.png" + "</wp:BackBackgroundImage>" +
                    "<wp:BackTitle Action=\"Clear\">" + "BackTitle" + "</wp:BackTitle>" +
                    "<wp:BackContent Action=\"Clear\">" + "Welcome Back!" + "</wp:BackContent>" +
                "</wp:Tile>" +
            "</wp:Notification>";

and send it by using:

hub.SendMpnsNativeNotificationAsync(tile);

Any help or guidance would be appreciated. Thanks.


Solution

  • I've located the problem. My xml was obviously in error, though I am not sure exactly what the cause of the problem was. Here is working XML if anyone is struggling.

    string tile = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<wp:Notification xmlns:wp=\"WPNotification\">" +
                        "<wp:Tile>" +
                          "<wp:BackgroundImage>" + backgroundImage + "</wp:BackgroundImage>" +
                          "<wp:Count>" + count + "</wp:Count>" +
                          "<wp:Title>" + Title + "</wp:Title>" +
                          "<wp:BackBackgroundImage>" + backBackgroundImg + "</wp:BackBackgroundImage>" +
                          "<wp:BackTitle>" + backTitle + "</wp:BackTitle>" +
                          "<wp:BackContent>" + backContent + "</wp:BackContent>" +
                       "</wp:Tile> " +
                    "</wp:Notification>";
    
                hub.SendMpnsNativeNotificationAsync(tile);