locked
When in snap view, code to intercept toast notifications is crashing the app and giving error "Object doesn't support property or method 'addEventListener'"

    Question

  • I am getting the error "Object doesn't support property or method 'addEventListener'" when my app is in snap view. This is my code

    function

    (channel) {

    varpushNotifications = Windows.Networking.PushNotifications;

       

    if(channel) {

            channel.addEventListener(

    "pushnotificationreceived", pushNotificationReceivedHandler);

        }

       

    varcontent;

       

    functionpushNotificationReceivedHandler(e) {

           

    varnotificationPayload;

           

    switch(e.notificationType) {

               

    casepushNotifications.PushNotificationType.toast:

                    notificationPayload = e.toastNotification.content.getXml();

                   

    break;

               

    casepushNotifications.PushNotificationType.tile:

                    notificationPayload = e.tileNotification.content.getXml();

                   

    break;

               

    casepushNotifications.PushNotificationType.badge:

                    notificationPayload = e.badgeNotification.content.getXml();

                   

    break;

               

    casepushNotifications.PushNotificationType.raw:

                    notificationPayload = e.rawNotification.content;

                   

    break;

            }

            e.cancel =

    true;

        }

    }

    Friday, October 3, 2014 11:04 AM

All replies

  • Hi eDreamz,

    So can I understand you as you only have the problem while the app is in snap view?

    I assume your channel is PushNotificationChannel class, your code looks fine, but the error message indicate you are not working with the correct object, could you validate it?

    Also if you could share us with a demo, that could be easier for us to troubleshoot the problem, only the code cannot help much.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, October 6, 2014 10:22 AM
    Moderator