Windows phone 8 windows phone应用未收到推送通知:解析
我已经按照文档中给出的所有步骤注册了Parse网站的推送通知。(我下载了默认项目并添加了事件处理程序来处理传入的toast通知) 和处理程序Windows phone 8 windows phone应用未收到推送通知:解析,windows-phone-8,push-notification,parse-platform,mpns,Windows Phone 8,Push Notification,Parse Platform,Mpns,我已经按照文档中给出的所有步骤注册了Parse网站的推送通知。(我下载了默认项目并添加了事件处理程序来处理传入的toast通知) 和处理程序 private void ParsePushOnToastNotificationReceived(object sender, NotificationEventArgs notificationEventArgs) { var s = new ShellToast(); s.Content = no
private void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
var s = new ShellToast();
s.Content = notificationEventArgs.Collection.Values.First();
s.Title = "My Toast";
s.Show();
}
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
await ParseAnalytics.TrackAppOpenedAsync();
}
当我在模拟器中运行应用程序时,它会注册应用程序,我可以在仪表板中验证它。但一旦我从网站发送推送通知,注册设备的数量将显示为0,并且应用程序不会收到通知
值得一提的是,这种行为并不一致。有时应用程序确实会收到通知。有人能说出我遗漏这一点或任何其他点的原因吗
需要注意的一点是,ShellToast.Show()只能在后台任务中使用。如果在应用程序位于前台时调用它,则不会显示toast。
因此,当您希望看到toast通知时,请确保您的应用程序不在前台。首先,只有在前台应用程序未运行时,才会显示toast通知
如果在收到推送通知时应用程序正在运行,则必须执行以下操作:
ParseClient.Initialize("x0uNa3Q164SVGKbH4mxZJaxWxsuYtslB5tVPj893",
"cXFv9RQAoray9xFdwdcZCHXrrkrM6KNd0WyN194H");
this.Startup += async (sender, args) =>
{
// This optional line tracks statistics around app opens, including push effectiveness:
ParseAnalytics.TrackAppOpens(RootFrame);
// By convention, the empty string is considered a "Broadcast" channel
// Note that we had to add "async" to the definition to use the await keyword
await ParsePush.SubscribeAsync("");
};
ParsePush.ToastNotificationReceived += ParsePushOnToastNotificationReceived;
void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
Deployment.Current.Dispatcher.BeginInvoke(()=>{
// do anything
MessageBox.Show("got notification");
});
}
如果您的应用程序未运行,操作系统将正确处理通知,您无需执行任何操作。谢谢。但仪表盘有什么问题?最初它显示注册了一个客户机。但当我按下消息后,它显示0个收件人。但是有一个问题。如果我在事件处理程序中设置了一个断点,那么即使没有显示toast,它至少也会达到这个断点。这意味着我一开始没有收到通知。抱歉,无法使用解析。是的,您应该点击事件处理程序中的断点,因此发送推送通知似乎无法正常工作。谢谢。但仪表盘有什么问题?最初它显示注册了一个客户机。但当我按下消息后,它显示0个收件人。但是有一个问题。如果我在事件处理程序中设置了一个断点,那么即使没有显示toast,它至少也会达到这个断点。这意味着我首先没有收到通知。我使用的是MVVM模式。这是我为应用程序启动事件注册的App.xaml.cs中唯一的一段代码。