我正在Windows Phone 8.1 (不是silverlight)中开发一个应用程序,它使用WNS接收原始推送通知。
当我通过Visual运行我的应用程序(在物理设备上运行,而不是在模拟器中)时,我总是收到推送通知(应用程序位于前台,背景中,手机锁定.)。所以我认为我的密码是正确的。
我的问题是在没有使用Visual的情况下运行我的应用程序。如果我按下设备上的"app图标“来插入应用程序并将其保存在前台,我会收到推送通知。但是,如果我转到电话菜单,或者锁定设备(不关闭应用程序),我不会收到推送通知,但是服务器说WNS已经成功发送。如果我再次将应用程序放到前台,我会再次收到推送通知.
因此,通过Visual总结:Init应用程序,我总是收到通知。Init应用程序通过设备,只接收WNS与应用程序在前台。服务器总是成功地发送WNS。
这是我接收WNS的代码:
public static void OnPushNotificationReceived(PushNotificationChannel channel, PushNotificationReceivedEventArgs e)
{
Debug.WriteLine("Received WNS notification");
string notificationContent = String.Empty;
switch (e.NotificationType)
{
case PushNotificationType.Badge:
Debug.WriteLine("Badge notifications not allowed");
return;
case PushNotificationType.Tile:
Debug.WriteLine("Tile notifications not allowed");
return;
case PushNotificationType.Toast:
Debug.WriteLine("Toast notifications not allowed");
return;
case PushNotificationType.Raw:
notificationContent = e.RawNotification.Content;
break;
}
processWnsNotification(notificationContent);
}
//Show local toast notification
private static void processWnsNotification(string notification)
{
ToastTemplateType toastTemplateXml = ToastTemplateType.ToastText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateXml);
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("New message"));
ToastNotification toast = new ToastNotification(toastXml);
if(toastNotifier == null)
{
toastNotifier = ToastNotificationManager.CreateToastNotifier();
}
toastNotifier.Show(toast);
}有人知道我做错了什么吗?我觉得这可能是配置问题..。但我一直在挖掘属性和配置文件,但没有成功。
非常感谢!!豪尔赫
发布于 2015-11-13 18:51:28
这是预期的行为,并且有很好的文档记录,只有在未挂起或注册了可以处理原始通知的background task时,应用程序才会接收原始推送通知。
当Visual打开时,您会收到它们,因为在附加调试器时,应用程序不会挂起。要调试应用程序的挂起,请转到View->Toolbars并启用Debug Location工具栏,然后启动应用程序,并从Lifecycle Events框中选择Suspend选项。您会注意到您的代码没有执行(用断点进行测试)。
通知可能由您的服务器发送,但不会由您的电话接收。您可能不会检查推送请求的响应,但是应该有一些迹象表明客户端不可用或类似的东西(状态代码表示可能)。
https://stackoverflow.com/questions/33674447
复制相似问题