Unity简易版的软件升级

所谓简易版,就是用户每次登陆软件时,发现新版本,就提示用户去下载全新软件


using System.Collections;
using UnityEngine;
using AssemblyCSharp;
using LitJson;
using System.Xml;
/***
 *简易软件大版本升级 
 * 
 */
using System;

public class UpdateScript{


    private ServiceVersionVo serviceVersionVo = new ServiceVersionVo();
    private string currentVersion = Application.version;//当前软件版本号

    private string serverVersion ;//服务器上软件版本号

    private string downloadPath;//应用下载链接

    /**
     * 检测升级
     */
    public IEnumerator  updateCheck () {
        WWW www = new WWW(APIS.UPDATE_INFO_JSON_URL);  //"http://33.10.66:8080/MaJiangManage/images/update.xml";//服务器上最新的软件版本信息存储文件
        yield return www;
        byte[] buffer = www.bytes;
        string returnxml = System.Text.Encoding.UTF8.GetString (buffer);
        //下面开始进行XML的解析
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(returnxml);
        XmlNodeList nodeList = xmlDoc.SelectSingleNode ("versions").ChildNodes;
        foreach(XmlNode xmlNodeVersion in nodeList){
            Version123 temp = new Version123();
            temp.title = xmlNodeVersion.SelectSingleNode ("title").InnerText;
            temp.url = xmlNodeVersion.SelectSingleNode ("url").InnerText;
            temp.note = xmlNodeVersion.SelectSingleNode ("note").InnerText;
            temp.version = xmlNodeVersion.SelectSingleNode ("versionname").InnerText;
            XmlElement xe =(XmlElement) xmlNodeVersion;
            if (xe.GetAttribute ("id") == "ios") {
                serviceVersionVo.ios = temp; 
                serviceVersionVo.ios.url += "l=zh&mt=8";
            } else if (xe.GetAttribute ("id") == "android") {
                serviceVersionVo.Android = temp;
            }
        }
        compareVersion ();

    }

    //对比版本虚
    public void compareVersion(){
        int currentVerCode;//当前版本号数字
        int serverVerCode;//服务器上版本号数字
        currentVersion = currentVersion.Replace (".", "");
        currentVerCode = int.Parse (currentVersion);
        Version123 versionTemp = new Version123();//版本信息
        //versionTemp = serviceVersionVo.Android;
        if (Application.platform == RuntimePlatform.Android) {
            versionTemp = serviceVersionVo.Android;
        } else if (Application.platform == RuntimePlatform.IPhonePlayer) {
            versionTemp = serviceVersionVo.ios;
        }

        if (versionTemp != null &&versionTemp.version !=null) {
            serverVersion = versionTemp.version;
            serverVersion = serverVersion.Replace (".", "");
            serverVerCode = int.Parse (serverVersion);
            if (serverVerCode > currentVerCode) {//服务器上有新版本     
                string note = versionTemp.note;
                downloadPath = versionTemp.url;
                //实例化下载界面,并将下载方法与下载按钮挂钩
                TipsManagerScript.getInstance ().loadDialog ("发现新版本软件",note,onSureClick,onCancle); 
            }
        }
    }
    public void onSureClick(){
        if (downloadPath != null) {
            Application.OpenURL (downloadPath);  // 点击下载按钮,打开下载页面  
        }
    }

    public void onCancle(){

    }

}


FR:海涛高软(QQ技术交流群:386476712)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值