害怕问一个以前可能被问过的问题,但我的搜索技能却无法找到。好的,就到这里吧。
我有 Windows Phone 8 应用程序,当我的应用程序未在前台运行时,我可以在其中接收 TileUpdates 和通知。这是我按照http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202940(v=vs.105).aspx完成的
在那个链接中,我了解到为了在应用程序运行时获取通知,我应该简单地为接收案例附加一个事件。这是我在 AcquirePushChannel() 函数中所做的,如下所示:
public static void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("MyPushChannel");
CurrentChannel.Open();
if (!CurrentChannel.IsShellToastBound)
{
CurrentChannel.BindToShellTile();
}
CurrentChannel.BindToShellToast();
CurrentChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(Push_NotificationRecieved);
}
if (!CurrentChannel.IsShellTileBound)
{
CurrentChannel.BindToShellToast();
CurrentChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(Push_NotificationRecieved);
}
CurrentChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(Push_NotificationChannelChanged);
}
我已经实现了 CurrentChannel.ChannelUriUpdated,在 channelUri 发生变化的情况下,我执行了一些代码来更改我在云中的 ChannelsTable。我的 Push_NotificationRecieved 看起来像:
private static void Push_NotificationRecieved(object sender, NotificationEventArgs e)
{
StringBuilder message = new StringBuilder();
string relativeUri = string.Empty;
message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());
// Parse out the information that was part of the message.
foreach (string key in e.Collection.Keys)
{
message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);
if (string.Compare(
key,
"wp:Param",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.CompareOptions.IgnoreCase) == 0)
{
relativeUri = e.Collection[key];
}
}
// Display a dialog of all the fields in the toast.
MessageBox.Show(message.ToString());
//Dispatcher.BeginInvoke((message) => MessageBox.Show(message.ToString()));
}
我看不出为什么通知没有注册。因为在我的云登录中,我收到了 Toast 通知?
有任何想法吗?此外,据我所知,我可以从代码或类似的东西中显示吐司吗?
额外的
已尝试将功能更改为公共,但对问题没有帮助。任何人都知道为什么事件没有触发。