我的应用程序在关闭时能够接收到推送通知,但在运行时却没有任何反应。这段代码与之前在WindowsPhone8上使用的相同,并且没有遇到任何问题,但是新的应用程序正在运行WindowsPhone8.1设备。
我在创建原始应用程序时使用了Push 教程。我已经添加了一行代码,以便在应用程序打开时接收通知。
如果8.1更新对推送通知进行了更改,那么希望能得到通知。也感谢其他任何建议。
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];
}
}
}