我正在尝试在JS Metro应用程序中实现推送通知。我正在注册推送通知并获取通道URI。如果Channel URI是new我在我的WCF服务上更新它,我在本地机器上创建并托管它。 在我的服务中,我首先使用WNS进行身份验证并获取访问令牌和其他详细信息。然后我在通道URI上创建一个请求,在头文件中使用access-token。作为回应,我收到了“已收到”的“徽章”,“瓷砖”和“吐司”通知请求。
但我的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 Apps中实施推送通知的推荐方法是什么? 3.我是否必须附加后台任务才能收听推送通知?
任何代码示例都会很棒。
感谢。
答案 0 :(得分:1)
注意: - 要在项目中查看推送通知支持,您需要在“应用程序中设置以下属性” ToastCapable =是“ “ Package.appxmanifest 文件的标签。
希望它可以帮助你。
谢谢, Joy Oyiess Rex