locked
The onpushnotificationreceived event is not getting fired in windows 8 metro using javascript

    Question

  • On receiving notification from the server, the onpushnotificationreceived event is not getting fired in windows 8 metro using javascript

    Thursday, September 26, 2013 7:19 AM

All replies

  • I am not sure how we can help with no context or what you have done to troubleshoot this so far.

    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, September 26, 2013 7:53 PM
    Moderator
  • On receiving notification from the server, the onpushnotificationreceived event is not getting fired in windows 8 metro using javascript.

    The following is my code , if you could help me :

        Windows.Networking.PushNotifications.PushNotificationChannelManager
        .createPushNotificationChannelForApplicationAsync()
        .done(function (channel) {       
            channel.onpushnotificationreceived = pushNotificationReceivedHandler;        

            });

    Then I am defining the event listner function as follows :

    function pushNotificationReceivedHandler(e) {

    // functionality

    }

    The problem is that , the pushNotificationReceivedHandler function is not getting fired even if I receive the notification.


    Monday, October 21, 2013 10:34 AM
  • The problem is that you are not sending the notification channel to a server and the server would need to then send a correctly formatted message to the WNS server in order for you application to receive the message.  Just creating the notification channel is not enough in this case.

    You can use your own service or a service like Windows Azure Mobile Services to send push notifications.  Here is an example of the former and the latter:

    Walkthrough–Creating an IIS server to use with WNS Push Notifications and Windows Store apps

    Get started with push


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, October 21, 2013 11:35 AM
    Moderator
  • Here is the entire code including server call :

    var applicationData = Windows.Storage.ApplicationData.current;
        var localSettings = applicationData.localSettings;
        var localChannelURL = localSettings.values[gChannelURL];
        Windows.Networking.PushNotifications.PushNotificationChannelManager
        .createPushNotificationChannelForApplicationAsync()
        .done(function (channel) {
            var currChannelURL = channel.uri;

            channel.onpushnotificationreceived = pushNotificationReceivedHandler;
            channel.addEventListener("click", pushNotificationClickHandler);

                var notificationServerURL = WinJS.Resources.getString("NOTIFICATIONSERVERURL").value;

                var udid = new UDID.UDID();
                var deviceid = udid.getUDID();
                var devicetype = gNotificationDeviceType;
                var appid = appzillon.plugin.appId();

                gNotifictaionDeviceId = deviceid;

               // Here I used to call the server.

    });

    // NOTIFICATIONSERVERURL is the global variable which contains the server url for notification.

    Monday, October 21, 2013 12:05 PM