Answered by:
Message Notifications, almost working

Question
-
I've manged to cobble together what I think should work for metro notifications.
By using the program put together by Mike here ( http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2012/06/08/windows-8-metro-style-app-simple-wns-push-notification.aspx ) and using the sample JavaScript app here: "Push and periodic notifications client-side sample".
I've managed to create the callback url I believe correctly, the auth token and my JavaScript manages to Open the communication channel using Windows.Networking.PushNotifications.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();
Using Mike's program, I can send the message and Mike's program says "message appears to be sent successfully".
Even though my JS app claims to be listening correctly, when I sent messages, nothing goes through my switch statement.
How can I debug this?
Thanks
function startListening() { var channel = SampleNotifications.currentChannel; if (channel) { channel.addEventListener("pushnotificationreceived", pushNotificationReceivedHandler); console.log("Now listening for push notification events.", "sample", "status"); } else { console.log("No channel is open.", "sample", "error"); } } var pushNotifications = Windows.Networking.PushNotifications; function pushNotificationReceivedHandler(e) { var notificationTypeName = ""; var notificationPayload = "unassigned"; 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; } // Setting the cancel property prevents the notification from being delivered. It's especially important to do this for toasts: // if your application is already on the screen, there's no need to display a toast from push notifications. //e.cancel = true; //WinJS.log(notificationTypeName + " notification was received and canceled. Notification payload: " + notificationPayload, "sample", "status"); }
Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
Saturday, July 21, 2012 12:55 AM
Answers
-
through tons of trial and error, I did finally get this working so I am closing this question.
Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
- Marked as answer by Peter Kellner Monday, July 23, 2012 3:34 AM
Monday, July 23, 2012 3:34 AM
All replies
-
through tons of trial and error, I did finally get this working so I am closing this question.
Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
- Marked as answer by Peter Kellner Monday, July 23, 2012 3:34 AM
Monday, July 23, 2012 3:34 AM -
Hi,
I'm glad to hear that you resolve this issue.
If you can share your solutions and experience here, it will be very beneficial for other community members who have similar questions.
If you have any difficulty in future programming, we welcome you to post in forums again.Best Regards,
Ming Xu.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code FrameworkWednesday, July 25, 2012 5:22 AMModerator