Currently, I am in the process of integrating push notifications into a JS Metro app. After registering for push notifications and obtaining a Channel URI, I update it in my locally hosted WCF service if it is new. Within my service, I authenticate with WNS to receive the necessary access-token and other details. Subsequently, I send a request to the Channel URI with the access-token in the header. The response typically indicates that the "badge", "tile", and "toast" notification requests have been received.
Despite this, I am not receiving any notifications in my JS Metro app. Below is the code I am using to register for push notifications and to listen for them.
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;
// I also update the Channel URI on my WCF service here
});
} catch (e) { }
}
function notificationReceived(e, args) {
var notificationTypeName = "";
var notificationPayload;
switch (e.notificationType) {
// Getting the toast, tile, or badge notification object and displaying the XML content.
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;
}
}
I would appreciate any insights on why this issue is occurring. Additionally, I am seeking recommendations on the best approach to implement push notifications in Windows 8 JavaScript Metro Apps. Do I need to include a background task to listen for push notifications?
Any code samples or guidance on this matter would be greatly helpful.
Thank you.