Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
Created August 3, 2012 23:42
Show Gist options
  • Save ferclaverino/3252745 to your computer and use it in GitHub Desktop.
Save ferclaverino/3252745 to your computer and use it in GitHub Desktop.
a module to register to WNS
(function () {
"use strict";
function request() {
var WNSRegistrationUrl = ApplicationConfiguration.getServiceRootSite() + "/MyService/Register";
var notificationChannel = Windows.Networking.PushNotifications.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();
notificationChannel
.then(function (channel) {
// suscribo al evento de notificacion recibida p/limpiar el cache
channel.addEventListener("pushnotificationreceived", onPushNotificationReceived);
var URIdata = '{"URI":"' + channel.uri + '"}';
return WinJS.xhr({
type: "POST",
url: WNSRegistrationUrl,
headers: { "Content-Type": "application/json; charset=utf-8" },
data: URIdata
});
}).then(function (response) {
var status = response;
});
}
function onPushNotificationReceived(eventArgs) {
var homeNewsQuery = new Queries.HomeNewsCachedQuery();
homeNewsQuery.flushCache();
}
// Export public methods
WinJS.Namespace.define("PushNotification",
{
request: request
}
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment