WP7应用版本升级的实现方法

本文介绍了一个移动应用在启动时检查更新的方法。通过调用服务端提供的API接口来判断当前应用是否需要更新,并在必要时提示用户进行更新操作。
首先必须要有一个服务提供升级推送查询
// Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            updateServiceReference.UpdateSoapClient usp = new updateServiceReference.UpdateSoapClient();
            usp.CheckMobileUpdateCompleted += new EventHandler<updateServiceReference.CheckMobileUpdateCompletedEventArgs>(usp_CheckMobileUpdateCompleted);
            usp.CheckMobileUpdateAsync(1);
        }
 
        void usp_CheckMobileUpdateCompleted(object sender, updateServiceReference.CheckMobileUpdateCompletedEventArgs e)
        {
            if (e.Result == null)
            {
                return;
            }
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            //string version = System.Reflection.Assembly.GetExecutingAssembly().FullName;
            //获取程序集的版本号,然后去掉.得到数字对比大小
            string version = assembly.GetCustomAttributes(false).OfType<System.Reflection.AssemblyFileVersionAttribute>().First().Version;
            if (int.Parse(e.Result.Ver) > int.Parse(version.Replace(".", "")))
            {
                if (MessageBox.Show(e.Result.UpdateLog, "升级提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    Microsoft.Phone.Tasks.MarketplaceDetailTask ms = new Microsoft.Phone.Tasks.MarketplaceDetailTask();
                    ms.ContentType = Microsoft.Phone.Tasks.MarketplaceContentType.Applications;
                    ms.ContentIdentifier = e.Result.DownPath;
                    ms.Show();
                }
            }
        }

转载于:https://www.cnblogs.com/leestar54/p/3220430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值