Push notification 未收到推送通知,windows universal 8.1

Push notification 未收到推送通知,windows universal 8.1,push-notification,windows-phone-8.1,azure-notificationhub,Push Notification,Windows Phone 8.1,Azure Notificationhub,您好,我已经在我的应用程序中实现了推送通知,serer正在发送通知,但在我端没有接收 void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { string typeString = String.Empty; string notificationContent =

您好,我已经在我的应用程序中实现了推送通知,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
            {

            }
        }
void OnPushNotificationReceived(PushNotificationChannel发送方,PushNotificationReceivedEventArgs e)
{
string typeString=string.Empty;
string notificationContent=string.Empty;
开关(如NotificationType)
{
案例提示类型。徽章:
typeString=“徽章”;
notificationContent=e.BadgeNotification.Content.GetXml();
打破
案例PushNotificationType.Tile:
notificationContent=e.TileNotification.Content.GetXml();
typeString=“Tile”;
打破
案例PushNotificationType.Toast:
notificationContent=e.ToastNotification.Content.GetXml();
typeString=“Toast”;
//设置cancel属性会阻止通知的传递。在祝酒时执行此操作尤其重要:
//如果您的应用程序已在屏幕上,则无需显示推送通知中的toast。
e、 取消=真;
打破
案例PushNotificationType.Raw:
notificationContent=e.RawNotification.Content;
typeString=“原始”;
打破
}
//string text=“收到一个“+typeString+”通知,包含:“+notificationContent;
忽略var=dispatcher.RunAsync(CoreDispatcherPriority.Normal,()=>
{
//NotifyUser(文本,NotifyType.StatusMessage);
if(typeString==“Toast”)
{
PushNotificationHelper.AddTosNotification(0,notificationContent);
}
else if(类型字符串==“徽章”)
{
PushNotificationHelper.AddBadgeNotification(0,notificationContent);
}
});
}
公共异步void InitChannel()
{
Windows.Storage.ApplicationDataContainer roamingSettings=Windows.Storage.ApplicationData.Current.LocalSettings;
尝试
{
var channel=等待PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
如果(通道!=null)
{
//字符串existingChannel=(字符串)漫游设置。值[“ExistingPushChannel”];
roamingSettings.Values[“ExistingPushChannel”]=channel.Uri;
dispatcher=Windows.UI.Core.CoreWindow.GetForCurrentThread().dispatcher;
channel.PushNotificationReceived+=OnPushNotificationReceived;
}
其他的
{
roamingSettings.Values[“ExistingPushChannel”]=“未能创建频道”;
}
}
抓住
{
roamingSettings.Values[“ExistingPushChannel”]=“未能创建频道”;
}
}
公共异步void InitNotificationsAsync()
{
尝试
{
Windows.Storage.ApplicationDataContainer roamingSettings=Windows.Storage.ApplicationData.Current.LocalSettings;
字符串existingChannel=(字符串)漫游设置。值[“ExistingPushChannel”];
字符串tempDevelopmentKey=“”;
字符串平台=”;
List arrayTags=新列表();
#如果WINDOWS\u应用程序
平台=“windows平板电脑”;
tempDevelopmentKey=“dev_WindowsTabletNotification”;
#恩迪夫
#如果WINDOWS\u PHONE\u应用程序
Platform=“windows phone”;
tempDevelopmentKey=“dev_WindowsPhoneNotification”;
#恩迪夫
阵列标签。添加(平台);
arrayTags.Add(tempDevelopmentKey);
字符串TMBNotification=(字符串)roamingSettings.Values[“TMBNotification”];
if(TMBNotification!=null)
{
如果(TMB通知==“开启”)
{
阵列标签添加(“TMB”);
}
}
字符串TRSNotification=(字符串)漫游设置。值[“TRSNotification”];
if(TRSNotification!=null)
{
如果(TRSNotification==“开”)
{
阵列标签添加(“TRS”);
}
}
字符串IMNotification=(字符串)roamingSettings.Values[“IMNotification”];
if(IMNotification!=null)
{
如果(IMNotification==“on”)
{
阵列标签。添加(“IM”);
}
}
字符串SWSNotification=(字符串)漫游设置。值[“SWSNotification”];
if(SWSNotification!=null)
{
如果(SWSNotification==“开”)
{
阵列标签添加(“ANC”);
}
}
字符串VIDNotification=(字符串)漫游设置。值[“VIDNotification”];
如果(VIDNotification!=null)
{
如果(VIDNotification==“打开”)
{
添加(“视频”);
}
}
var hub=新通知中心(“hubname”、“endpoint”);
var result=wait hub.RegisterNativeAsync(现有通道、阵列标签);
//显示注册ID,以便您知道注册成功
if(result.RegistrationId!=null)
{
}
}抓住