未收到推送通知,Windows通用8.1

时间:2015-03-20 08:58:12

标签: push-notification windows-phone-8.1 azure-notificationhub

我已经在我的应用程序中实现了推送通知,serer正在发送通知但未在我的终端接收。

          void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
        {
            string typeString = String.Empty;
            string notificationContent = String.Empty;
            switch (e.NotificationType)
            {
                case PushNotificationType.Badge:
                    typeString = "Badge";
                    notificationContent = e.BadgeNotification.Content.GetXml();
                    break;
                case PushNotificationType.Tile:
                    notificationContent = e.TileNotification.Content.GetXml();
                    typeString = "Tile";
                    break;
                case PushNotificationType.Toast:
                    notificationContent = e.ToastNotification.Content.GetXml();
                    typeString = "Toast";
                    // Setting the cancel property prevents the notification from being delivered. It's especially important to do this for toasts:
                    // if your application is already on the screen, there's no need to display a toast from push notifications.
                    e.Cancel = true;
                    break;
                case PushNotificationType.Raw:
                    notificationContent = e.RawNotification.Content;
                    typeString = "Raw";
                    break;
            }

            //   string text = "Received a " + typeString + " notification, containing: " + notificationContent;
            var ignored = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // rootPage.NotifyUser(text, NotifyType.StatusMessage);

                if (typeString == "Toast")
                {
                    PushNotificationHelper.AddTostNotification(0, notificationContent);
                }
                else if (typeString == "Badge")
                {
                    PushNotificationHelper.AddBadgeNotification(0, notificationContent);
                }

            });
        }

        public async void InitChannel()
        {
            Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            try
            {
                var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                if (channel != null)
                {

                    //String existingChannel = (String)roamingSettings.Values["ExistingPushChannel"];
                    roamingSettings.Values["ExistingPushChannel"] = channel.Uri;

                    dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
                    channel.PushNotificationReceived += OnPushNotificationReceived;

                }
                else
                {
                    roamingSettings.Values["ExistingPushChannel"] = "Failed to create channel";
                }
            }
            catch
            {
                roamingSettings.Values["ExistingPushChannel"] = "Failed to create channel";
            }
        }

        public async void InitNotificationsAsync()
        {
            try
            {
                Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                String existingChannel = (String)roamingSettings.Values["ExistingPushChannel"];

                string tempDevelopmentKey = "";
                string Platform = "";

                List<string> arrayTags = new List<string>();

#if WINDOWS_APP
                Platform = "windows-tablet";
             tempDevelopmentKey = "dev_WindowsTabletNotification";
#endif

#if WINDOWS_PHONE_APP
            Platform = "windows-phone";
            tempDevelopmentKey ="dev_WindowsPhoneNotification";
#endif

                arrayTags.Add(Platform) ;
                arrayTags.Add(tempDevelopmentKey) ;

                string TMBNotification = (string)roamingSettings.Values["TMBNotification"];
                if(TMBNotification != null)
                {
                    if(TMBNotification == "on")
                    {
                        arrayTags.Add("TMB");
                    }
                }
                string TRSNotification = (string)roamingSettings.Values["TRSNotification"];
                if (TRSNotification != null)
                {
                    if (TRSNotification == "on")
                    {
                        arrayTags.Add("TRS");
                    }
                }
                string IMNotification = (string)roamingSettings.Values["IMNotification"];
                if (IMNotification != null)
                {
                    if (IMNotification == "on")
                    {
                        arrayTags.Add("IM");
                    }
                }
                string SWSNotification = (string)roamingSettings.Values["SWSNotification"];
                if (SWSNotification != null)
                {
                    if (SWSNotification == "on")
                    {
                        arrayTags.Add("ANC");
                    }
                }
                string VIDNotification = (string)roamingSettings.Values["VIDNotification"];
                if (VIDNotification != null)
                {
                    if (VIDNotification == "on")
                    {
                        arrayTags.Add("videos");
                    }
                }


                var hub = new NotificationHub("hubname", "endpoint");
                var result = await hub.RegisterNativeAsync(existingChannel, arrayTags);

                // Displays the registration ID so you know it was successful
                if (result.RegistrationId != null)
                {

                }

            }catch
            {

            }
        }

那么我如何确认我的实现中没有问题,或者服务器端存在问题。

1 个答案:

答案 0 :(得分:2)

您可以采取以下几个步骤来调试此问题: -

  • 有广播和发送通知,使用通知集线器,天蓝色门户网站上可用的选项(您也可以从VS左侧服务器资源管理器进行)。执行此操作时,会有一个日志,显示是否成功发送通知。
  • 首先删除所有注册通知中心,并进行非常新的注册检查,您的设备是否使用正确的标签/通道uri注册(这也是您从服务器资源管理器中执行的)
  • 确保您sending/registering是与WNS服务相对应的正确模板。
  • 确保您使用的WNS服务与以下内容不同 WP8 silverlight one。

    ServerExplorer

如果有的话,您可以在此页面底部看到错误。 您可以选择设备注册来更改注册。

  • DebugNotificationHUb