Search code examples
c#windows-phone-8pushsharp

Multiple callback for one notification pushsharp window phone


I am using standart push notification code for window phone using pushsharp. I am getting notification on the device. But problem is that i am getting multiple callback for each event. such as, for one notification, i am getting 5 callback for channel created, notificationsent etc.

Please help me where am i doing wrong.

 var push = new PushBroker();

        push.OnChannelCreated += push_OnChannelCreated;
        push.OnChannelDestroyed += push_OnChannelDestroyed;
        push.OnChannelException += push_OnChannelException;
        push.OnDeviceSubscriptionChanged += push_OnDeviceSubscriptionChanged;
        push.OnDeviceSubscriptionExpired += push_OnDeviceSubscriptionExpired;
        push.OnNotificationFailed += push_OnNotificationFailed;
        push.OnNotificationRequeue += push_OnNotificationRequeue;
        push.OnNotificationSent += push_OnNotificationSent;
        push.OnServiceException += push_OnServiceException;

        push.RegisterWindowsService(new WindowsPushChannelSettings("NotificationFra",
           "ms-app://s-1-15-2-", "bJl6kdPqXWtOclINfKNC"));
        //Fluent construction of a Windows Toast Notification
        push.QueueNotification(new WindowsToastNotification().WithLaunch("{\"message\":\"Hi PushNotification\",\"messageToken\":\"AbCD1A3@\",\"notificationType\":3}")
            .AsToastText01("Notification Test for Daily alerts intrade FTD MTD ")
            .ForChannelUri("https://hk2.notify.windows.com/?token=AwYAAAA%2b21ScKkaVZhp5vwRRPn7DWlEqvzKmTXy%2bNfcONUzq9PeglhxTLlD06%2fiLcgyuu9BbdeuY8Pgl"));

        push.StopAllServices(waitForQueuesToFinish: true);

Solution

  • I got solution from the support team,

    Please don't RegisterWindowsService() (or RegisterWindowsPhoneService()) when you want to send just one kind of notifications (WindowsToastNotification (or rather WindowsPhoneToastNotification) in your case). Those methods internally do multiple registrations for all kind of notifications. And coupled with another bug - you get N callbacks instead of one.

    Use generic RegisterService (or rather RegisterService).

    Based on above solution i have used below code for registration :

        var channel = new WindowsPushChannelSettings("NotificationFra", "ms-app://s-1-15-2-3763039301-", "bJl6kdPqXWtOclINfKNC");
            push.RegisterService<WindowsToastNotification>(new WindowsPushService(channel));