C# 应用程序打开时推送不显示
当应用程序关闭时,我的应用程序可以很好地接收推送通知。但当应用程序运行时,我什么也得不到。这与我在以前的应用程序中使用的代码相同,没有任何问题,这些应用程序是在WindowsPhone8上使用的,而新的应用程序是在WindowsPhone8.1设备上运行的 我在制作原始应用程序时使用了这个。我有一句话说,如果你想在应用程序打开时收到通知,就添加这个 如果8.1更新对推送通知做了一些事情,那么最好了解一下。其他任何事情都将不胜感激C# 应用程序打开时推送不显示,c#,.net,windows-phone-8,windows-phone-8.1,C#,.net,Windows Phone 8,Windows Phone 8.1,当应用程序关闭时,我的应用程序可以很好地接收推送通知。但当应用程序运行时,我什么也得不到。这与我在以前的应用程序中使用的代码相同,没有任何问题,这些应用程序是在WindowsPhone8上使用的,而新的应用程序是在WindowsPhone8.1设备上运行的 我在制作原始应用程序时使用了这个。我有一句话说,如果你想在应用程序打开时收到通知,就添加这个 如果8.1更新对推送通知做了一些事情,那么最好了解一下。其他任何事情都将不胜感激 HttpNotificationChannel pushChann
HttpNotificationChannel pushChannel;
string channelName = "PushChannel";
pushChannel = HttpNotificationChannel.Find(channelName);
//Push Notifications
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
//// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated +=
new EventHandler<NotificationChannelUriEventArgs>(
PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred +=
new EventHandler<NotificationChannelErrorEventArgs>(
PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive
// the notifications while your application is running.
pushChannel.ShellToastNotificationReceived +=
new EventHandler<NotificationEventArgs>(
PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
// Bind this new channel for toast events.
pushChannel.BindToShellToast();
}
else...
void PushChannel_ShellToastNotificationReceived(object sender,
NotificationEventArgs e)
{
string relativeUri = string.Empty;
// Parse out the information that was part of the message.
foreach (string key in e.Collection.Keys)
{
if (string.Compare(
key,
"wp:Param",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.CompareOptions.IgnoreCase) == 0)
{
relativeUri = e.Collection[key];
}
}
}
HttpNotificationChannel推送通道;
字符串channelName=“PushChannel”;
pushChannel=HttpNotificationChannel.Find(channelName);
//推送通知
if(pushChannel==null)
{
pushChannel=新的HttpNotificationChannel(通道名称);
////在尝试打开通道之前注册所有事件。
pushChannel.ChannelUriUpdated+=
新事件处理程序(
PushChannel_CHANNEL更新);
pushChannel.ErrorOccessed+=
新事件处理程序(
推送通道(发生错误);
//仅当需要接收时才注册此通知
//应用程序运行时的通知。
pushChannel.ShellToastNotificationReceived+=
新事件处理程序(
推送通道(外壳至接收到的通知);
pushChannel.Open();
//为toast事件绑定此新频道。
pushChannel.BindToShellToast();
}
其他的
无效PushChannel_ShellToastNotificationReceived(对象发送方,
通知事件参数(e)
{
string relativeUri=string.Empty;
//解析出作为消息一部分的信息。
foreach(e.Collection.Keys中的字符串键)
{
if(string.Compare)(
钥匙
“wp:Param”,
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.CompareOptions.IgnoreCase)==0)
{
relativeUri=e.Collection[key];
}
}
}
罗布·卡普兰:
当应用程序位于前台时,不会显示祝酒词。如果需要,该应用程序将显示自己的UI(您的代码片段不会显示任何内容)。这就是ShellToastNotificationReceived事件的作用:它在toast通知到达而不是toast出现时激发。你能确认ShellToastNotificationReceived没有在你期待祝酒的时候发出吗?应该是。您能否确认它已在调试器中注册并接收(或未接收)?请参阅msdn.microsoft.com/en-us/library/windows/apps/ 我:
在8.1更新之前,当打开的应用程序收到推送时,祝酒词仍会显示。我刚刚做了一些测试,果然,“PushChannel\u ShellToastNotificationReceived”事件仍在被触发,但toast没有显示出来。我想这只是意味着我需要用不同的方式来处理它。如果你想把它变成一个答案,我可以奖励它。请显示一些代码。您使用的是MPNS还是WNS?添加了代码。否则,只需将事件处理程序添加到已经存在的PushChannel中。简言之,ShellToastNotificationReceived不会触发。不是吗?toast通知根本没有显示,就好像推送侦听器没有侦听一样。我不知道这到底有多真实,但我认为单击toast通知时会触发ShellToastNotificationReceived。但我没有收到任何祝酒词,因为当应用程序在前台时,我们不希望看到任何祝酒词。如果需要,该应用程序将显示自己的UI(您的代码片段不会显示任何内容)。这就是ShellToastNotificationReceived事件的作用:它在toast通知到达而不是toast出现时激发。你能确认ShellToastNotificationReceived没有在你期待祝酒的时候发出吗?应该是。您能否确认它已在调试器中注册并接收(或未接收)?看见