0

我试图在JS Metro应用程序中实现推送通知。我正在注册推送通知并获取通道URI。如果Channel URI是新的,我在我的本地机器上创建和托管的WCF服务上进行更新。 在我的服务中,我首先与WNS进行身份验证并获取访问令牌和其他详细信息。然后我在Channel头部使用access-token创建一个请求。作为回应,我收到我收到的“徽章”,“瓦片”和“吐司”通知请求。推送通知不在JS地铁应用程序中接收

但我的JS Metro应用程序没有收到通知。以下是注册推送通知和侦听推送通知的代码。

var push = Windows.Networking.PushNotifications; 
var promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync(); 
var channel; 

function RegisterPNWin() { 
try { 
    push = Windows.Networking.PushNotifications; 
    promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync(); 

    promise.then(function (ch) { 
     channel = ch; 
     channel.addEventListener("pushnotificationreceived", notificationReceived);   
     var uri = ch.uri; 
     var expiry = ch.expirationTime; 

// here I update Channel URI on my WCF service   
    }); 
} catch (e) { } 
} 

function notificationReceived(e, args) { 
var notificationTypeName = ""; 
var notificationPayload; 
switch (e.notificationType) { 
    // You can get the toast, tile, or badge notification object. 
    // In this example, we take the XML from that notification and display it. 
    case pushNotifications.PushNotificationType.toast: 
     notificationTypeName = "Toast"; 
     notificationPayload = e.toastNotification.content.getXml(); 
     break; 
    case pushNotifications.PushNotificationType.tile: 
     notificationTypeName = "Tile"; 
     notificationPayload = e.tileNotification.content.getXml(); 
     break; 
    case pushNotifications.PushNotificationType.badge: 
     notificationTypeName = "Badge"; 
     notificationPayload = e.badgeNotification.content.getXml(); 
     break; 
    case pushNotifications.PushNotificationType.raw: 
     notificationTypeName = "Raw"; 
     notificationPayload = e.rawNotification.content; 
     break; 
} 
} 

请让我知道如果我失去了一些东西。 1.为什么会发生这种情况? 2.在Windows 8 JavaScript Metro应用程序中实施推送通知的推荐方式是什么? 3.我是否需要附加后台任务才能收听推送通知?

任何代码示例都会很棒。

谢谢。

+0

觉得你认真倾听只有当应用程序被激活将被解雇(如在屏幕上),而不是挂起的事件。你正在测试它吗?要在暂停时获得通知,您需要后台任务。 –

+0

是的,我在应用程序处于活动状态时正在测试它。 – Deeps

+0

一个好的步骤是将你的客户端与你的后端分开调试。您能否使用Push和Periodic Notifications客户端示例尝试您的服务? (http://code.msdn.microsoft.com/windowsapps/Push-and-periodic-de225603)因为XML最简单,所以我建议使用这个测试的徽章通知。方案1和3是你想要的。它看起来像是直接从样本中抽取了一些代码,但使用它会消除客户是否做正确的事情的问题。 –

回答

1

注: - 为了在项目中查看推送通知支持,你需要设置以下属性,“ToastCapable =是”在包的“应用”选项卡。 appxmanifest文件。

希望它可以帮助你。

感谢, 喜悦Oyiess雷克斯

+0

嗨,欢乐,请告诉我如何接收应用程序关闭时的吐司/瓷砖/徽章通知。 – Deeps

+0

Hi @Deeps,Windows推送通知服务(WNS)仅在通知的目标应用程序处于前台时发送此事件。如果应用程序被暂停,它不会收到该事件。 –

+0

您需要使用为推送通知触发器注册的后台任务。 –

相关问题