Windows8 提示用户去商店下载新版本

 

       软件版本需要不断的迭代升级,当微软商店再次审核通过时,一方面,系统自带的 "应用商店" 会提示用户下载新版本,

但是,最好在自己的软件中,也实现检测最新版本软件的功能,并提示用户下载更新。

 

       实现效果,当检测到服务器端有新版本数据时,弹出提示框:

 

当用户点击 "立即更新" 时, 即跳转到  "应用商店" 相应的下载页面进行下载。

 

代码 :

//当检测到有新版本时,弹出对话框
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,async delegate { var messageDialog = new MessageDialog("XX有新版本啦~快来尝个鲜吧~"); // 添加 命令 并且设置为同一个回调方法 messageDialog.Commands.Add(new UICommand( "立即更新", new UICommandInvokedHandler(this.CommandInvokedHandler))); messageDialog.Commands.Add(new UICommand( "稍后再说", new UICommandInvokedHandler(this.CommandInvokedHandler))); // 默认调用第一个命令 messageDialog.DefaultCommandIndex = 0; // 设置第二个命令为 “取消” 命令 messageDialog.CancelCommandIndex = 1; await messageDialog.ShowAsync(); });

 

回调函数中, 如果是 “立即更新” 的命令, 则根据 "包系列名称" 打开应用商店:

 private async void CommandInvokedHandler(IUICommand command)
 {
     if (command.Label == "立即更新")
     {
         var uri = new Uri(@"ms-windows-store:PDP?PFN=你应用的‘包系列名称’");
         await Windows.System.Launcher.LaunchUriAsync(uri);
     }
 }

 

"包系列名称" 在 Package.appxmanifest 文件中的 "打包选项卡" 中:

 

posted @ 2012-11-24 16:48  博琼  阅读(253)  评论(0编辑  收藏  举报