LucKy_one

Always aiming higher


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

向Windows8应用推送通知(Toast)并响应点击通知事件

发表于 2014-07-23 更新于 2014-08-03
介绍了如何在Azure中的Mobile Service服务器向Windows 8的客户端推送Toast,并且在客户端针对不同的Toast做出相应的操作。

在Mobile Service服务器端推送Toast

WindowsPushMessage message = new WindowsPushMessage();
message.XmlPayload = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
                     @"<toast launch=""toastTest"">"+  //launch后面的是传输给Onlaunch的参数
                     @"<visual><binding template=""ToastText01"">" +
                     @"<text id=""1"">" + item.Text+"/"+item.UserId+ @"</text>" +
                     @"</binding></visual></toast>";
try
{
    var result = await Services.Push.SendAsync(message);
    Services.Log.Info(result.State.ToString());
}
catch (System.Exception ex)
{
    Services.Log.Error(ex.Message, null, "Push.SendAsync Error");
}

当你点击Toast时会触发OnLaunched函数,参数内容可以在toast里面指定。这样就可以在OnLaunched根据参数做出指定的操作。

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    string launchString = e.Arguments;
    if (launchString.Equals("toastTest"))
    {
        TestToastLaunchBrowers();
    }
        …………
}

这里我们通过点击Toast来启动一个外部浏览器并打开一个URL:使用Windows.System.Launcher.LaunchUriAsync(Uri)该方法可以在windows8以及wp8中使用

async void TestToastLaunchBrowers()
{
    // Launch the URI
    var success = await Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.bing.com"));
}

参考文献:
How to handle activation from a toast notification (XAML)

# windows8开发
GZIP is not enough!网站压缩讲座总结
访问HubSection中的ListView(windows 8)

Liu Tianhe

喜欢金融,喜欢科技
31 日志
29 标签
RSS
GitHub E-Mail
© 2014 – 2022 Liu Tianhe
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Mist v7.3.0