【问题标题】:Managing toast notifications in windows store app 8.1在 Windows 商店应用程序 8.1 中管理 toast 通知
【发布时间】:2015-10-19 10:00:56
【问题描述】:

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

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

我想知道的是:首先,我如何处理收到通知的事件,其次,如果有一种方法可以在不同的页面中打开应用程序,当我单击 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'
});

【问题讨论】:

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


    【解决方案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 通知”的非常好的文章: 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:

    您可以使用启动参数来发送您想要的所有数据,而不仅仅是参数......即: 请参阅“启动=..”

    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].. 等等,你可以做一些正则表达式来取消它的格式:-)

    【讨论】:

    • 好的,现在我可以获取启动参数,但不确定如何从 toast 通知中提取文本。
    • Windows 8.1 RT 还是新的 WUP? “提取文本”是什么意思?
    • Windows 8.1。我的意思是从 toast 中获取文本 id="1"。
    • 我正在尝试“PushNotificationReceived”事件,它是在我收到原始通知时触发的,但是如果我在启动中有那个 json,它不会触发这个事件,不知道为什么,还有通知文本不显示,它只显示“新通知”,可能是我使用的 nodeJS 模块的问题 (npmjs.com/package/push-notify)
    • 我不知道为什么,可能是因为nodeJS推送模块..答案更新了,使用你自己的格式
    猜你喜欢
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多