一个通知的多个回调 pushsharp window phone

Multiple callback for one notification pushsharp window phone

我正在使用 pushsharp 为 window phone 使用标准推送通知代码。 我在设备上收到通知。但问题是 我收到每个事件的多个回调 。例如,对于一个通知,我收到 5 个针对已创建频道、已发送通知等的回调。

请帮我看看哪里做错了

 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);

我从支持团队那里得到了解决方案,

当您只想发送一种通知(在您的情况下是 WindowsToastNotification(或更确切地说是 WindowsPhoneToastNotification))时,请不要 RegisterWindowsService()(或 RegisterWindowsPhoneService())。这些方法在内部为各种通知进行多次注册。再加上另一个错误 - 你得到 N 个回调而不是一个。

使用通用 RegisterService(或者更确切地说是 RegisterService)。

基于上述解决方案,我使用以下代码进行注册:

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