Pregunta

I am trying to implement push notification in JS Metro app. I am registering for push notification and gets a channel URI. If the Channel URI is new I update it on my WCF service which I have created and hosted on my local machine. In my service I first authenticate with WNS and gets the access-token and other details. then I create a request on the Channel URI with access-token in header. In response I get "received" for "badge", "tile" and "toast" notification request I have sent.

But no notification is received in my JS Metro app. Below is the code for registering for push notification and listening for push notification.

var push = Windows.Networking.PushNotifications;
var promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();
var channel;

function RegisterPNWin() {
try {
    push = Windows.Networking.PushNotifications;
    promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();

    promise.then(function (ch) {
        channel = ch;
        channel.addEventListener("pushnotificationreceived", notificationReceived);           
        var uri = ch.uri;
        var expiry = ch.expirationTime;

 // here I update Channel URI on my WCF service         
    });
} catch (e) { }
}

function notificationReceived(e, args) {
var notificationTypeName = "";
var notificationPayload;
switch (e.notificationType) {
    // You can get the toast, tile, or badge notification object.
    // In this example, we take the XML from that notification and display it.
    case pushNotifications.PushNotificationType.toast:
        notificationTypeName = "Toast";
        notificationPayload = e.toastNotification.content.getXml();
        break;
    case pushNotifications.PushNotificationType.tile:
        notificationTypeName = "Tile";
        notificationPayload = e.tileNotification.content.getXml();
        break;
    case pushNotifications.PushNotificationType.badge:
        notificationTypeName = "Badge";
        notificationPayload = e.badgeNotification.content.getXml();
        break;
    case pushNotifications.PushNotificationType.raw:
        notificationTypeName = "Raw";
        notificationPayload = e.rawNotification.content;
        break;
}
}

Please let me know if I am missing something. 1. Why this is happening? 2. what is the recommended way to implement for push notification in Windows 8 javascript Metro Apps? 3. do I have to attach a background task to listen to push notification?

any code sample would be great.

thanks.

¿Fue útil?

Solución

Note :- In order to view the push notification support in your project, you need to set the following property, “ToastCapable = Yes” in the “Application” tab of the Package.appxmanifest file.

Hope it may helps you.

Thanks, Joy Oyiess Rex

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top