Just simple...
Create a backgroundTask.js with the code:
(function () {
"use strict";
var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;
var taskName = backgroundTask.task.name;
function doWork() {
var notificationContent = backgroundTaskInstance.triggerDetails.content;
close();
}
doWork();
})();
Then, declare var pushNotifications = Windows.Networking.PushNotifications;
on your default.js
Create a function (standalone or into a Namespace)...
registraTaskPush: function (){
var taskRegistered = false;
var exampleTaskName = "Push";
var iter = background.BackgroundTaskRegistration.allTasks.first();
while (iter.hasCurrent) {
var task = iter.current.value;
if (task.name === exampleTaskName) {
taskRegistered = true;
break;
}
iter.moveNext();
}
if (taskRegistered != true) {
var builder = new Windows.ApplicationModel.Background.BackgroundTaskBuilder();
var trigger = new Windows.ApplicationModel.Background.PushNotificationTrigger();
builder.name = exampleTaskName;
builder.taskEntryPoint = "js\\bgTasks.js";
builder.setTrigger(trigger);
var task = builder.register();
}
var channel;
var channelOperation = pushNotifications.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();
return channelOperation.then(function (newChannel) {
channel = newChannel;
$.ajax({
url: 'url/save/channel/in/database', type: 'POST',
data: { 'r': channel.uri, 'tp': 'windows' }
});
},
function (error) {
console.log('Error: '+error);
}
);
channel.addEventListener("pushnotificationreceived", onPushNotification, false);
}
Then...call the "registraTaskPush" function on your default.js after activation of the app.
"registraTaskPush" function implements the channel call to WNS and send to a server the channel URL to save on a database.
When the notification is started by server, the database returns all WNS URL's stored to code navigate between this URL's and send push for all.
In addition, "registraTaskPush" register the background task to Windows System, to receive push notifications even the app is closed.