Windows Phone 8.1 universal app, Navigate to a particular on tapping of receive Push Notification

315 views Asked by At

I am sending Push notification from Azure Notification hub. I want to navigate to particular page on tap of received Toast Push Notification. I am receiving Push notification but unable to navigate to a particular page.

Here is my insert code:

function insert(item, user, request) {
var payload = '<?xml version="1.0" encoding="utf-8"?><toast><visual>' +
    '<binding template="ToastText01">  <text id="1">' +
    item.subject + '</text></binding></visual></toast>';

request.execute({
    success: function () {
        // If the insert succeeds, send a notification.
        push.wns.send(null, payload, 'wns/toast', {
            success: function (pushResponse) {
                console.log("Sent push:", pushResponse);
                request.respond();
            },
            error: function (pushResponse) {
                console.log("Error Sending push:", pushResponse);
                request.respond(500, { error: pushResponse });
            }
        });
    }
});

}

Can any one please help?

1

There are 1 answers

2
Chris Anderson On

There is a number of steps here and you didn't give very much detail on your problem. I'll try to explain the concept in full of anyone who might need the whole thing. Be sure you've set up all the steps in this article first: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-windows-phone-get-started-push/

First, you need to send the push notification with the page you want to load. So let's say you have a page that shows some details about an item. When you get a push notification, it automatically opens up that item. You could send a payload like:

var payload = '<?xml version="1.0" encoding="utf-8"?><toast><visual>' +
    '<binding template="ToastText01">  <text id="1">' +
    item.id + '</text></binding></visual></toast>';

Then you need to respond to the push notification. You can see the documentation page for this here: https://msdn.microsoft.com/en-us/library/hh221550.aspx

Your set up code would look something like this:

ShellToastNotificationReceived += 
    new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);


public static HttpNotificationChannel CurrentChannel { get; private set; }

   // This is from the tutorial linked in the first paragraph
   private void AcquirePushChannel()
   {
       CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");

       if (CurrentChannel == null)
       {
           CurrentChannel = new HttpNotificationChannel("MyPushChannel");
           CurrentChannel.Open();
           CurrentChannel.BindToShellToast();
       }

       CurrentChannel.ChannelUriUpdated +=
           new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
           {

               // Register for notifications using the new channel
               await MobileService.GetPush()
                   .RegisterNativeAsync(CurrentChannel.ChannelUri.ToString());
           });

      CurrentChannel.ShellToastNotificationReceived +=
          new EventHandler<NotificationEventArgs(async (o, args) =>
          {
              RootFrame.Navigate(new Uri("/ItemPage.xaml"), args.Collection['1']);
          });
   }

I haven't tested any of this code, but it should be good enough to point you in the right directions. Basically,

  1. Send the info you need to react in the Push Notification
  2. Listen for event on your Client
  3. Navigate to the frame you want to be on

Be sure to checkout this tutorial on Navigation: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx