在Windows应用商店8.1中管理Toast通知

时间:2015-10-19 10:00:56

标签: c# xaml windows-runtime windows-store-apps toast

在Windows 8.1商店应用项目中,我希望能够接收Toast通知,然后在我的应用内管理它们的信息。

到目前为止,我有一个nodeJS服务器,它发送Toast通知并且运行良好。

我想知道的是:首先,我如何处理接收通知的事件,第二,如果有办法在不同页面打开应用程序,当我在Windows上单击Toast通知时,取决于我得到了什么吐司,例如,如果我得到一个祝福说“你好”我会点击它,应用程序将在hello.xaml页面打开,如果我有一个说“再见”我会在页面中打开应用程序再见的.xaml。

这是我在nodejs中发送的内容

wns.send({
    channelURI: 'https://db5.notify.windows.com/?token=ABCD',
    payload: '<toast launch="launch_arguments">'+
    '<visual>'+
    '<binding template="ToastText03">'+
    '<text id="1">Notification - ' + date.toDateString().replace(/T/, ' ').replace(/\..+/, '')+ ' ' + date.getHours() + ':'+date.getMinutes() + '.</text>'+
    '<text id="1">msg 123 test 456.</text>'+
    '<text id="1">bla bla bla bla</text>'+
    '</binding>'+
    '</visual>'+
    '</toast>',
    type: 'toast'
});

1 个答案:

答案 0 :(得分:1)

这是一个关于如何处理Toast通知的好主题:

http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/09/quickstart-sending-a-local-toast-notification-and-handling-activations-from-it-windows-10.aspx

这是一篇非常好的文章,关于互动式Toast通知&#39; : http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10.aspx

如果你想要它用于Windows 8.1,这里有一个很好的指导方针:

https://msdn.microsoft.com/en-us/library/windows/apps/hh761462.aspx https://msdn.microsoft.com/en-us/library/windows/apps/hh465391.aspx

更新1:

您可以使用启动参数发送您想要的所有数据,而不仅仅是参数...,即: 看&#34; launch = ..&#34;

wns.send({
    channelURI: 'https://db5.notify.windows.com/?token=ABCD',
    payload: '<toast launch="{\"params\":\"launch_arguments\",\"text\":\"Notification \",\"text_1\":\"msg 123 test 456\"}">'+
    '<visual>'+
    '<binding template="ToastText03">'+
    '<text id="1">Notification - ' + date.toDateString().replace(/T/, ' ').replace(/\..+/, '')+ ' ' + date.getHours() + ':'+date.getMinutes() + '.</text>'+
    '<text id="1">msg 123 test 456.</text>'+
    '<text id="1">bla bla bla bla</text>'+
    '</binding>'+
    '</visual>'+
    '</toast>',
    type: 'toast'
});

你可以编辑:

"{\"params\":\"launch_arguments\",\"text\":\"Notification \",\"text_1\":\"msg 123 test 456\"}"

而且,你可以通过un-json在你的App.cs中轻松阅读它......

参考:https://msdn.microsoft.com/en-us/library/hh868212.aspx

更新2:

你可以使用你自己的格式,而不是json ..我的意思是:param1:[val1],param2:[val2] ..等你可以做一些正则表达式来取消格式化: - )