Пример #1
0
    private void CheckUpdate()
    {
        if (Application.platform != RuntimePlatform.Android && Application.platform != RuntimePlatform.IPhonePlayer)
        {
            return;
        }

        if (Application.platform != RuntimePlatform.IPhonePlayer)
        {
            Utils.ShowMessagePanel("正在检查新版本...", messagePanel);
        }

        ResponseHandle handler = delegate(string jsonString){
            Debug.Log("GetCheckUpdate: " + jsonString);
            Utils.HideMessagePanel(messagePanel);
            //加入玩家已经游戏了,那么跳转到Gameplay Scene。否则什么都不需要坐。
            CheckUpdateResponse resp = JsonConvert.DeserializeObject <CheckUpdateResponse>(jsonString);
            if (resp.isNeedUpdate)
            {
                if (Application.platform == RuntimePlatform.Android)
                {
                    newVersion = resp.newVersion;
                    StartCoroutine(DownloadApk(resp.updateUrl));
                }
                else if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    Utils.ShowConfirmMessagePanel("发现新版本,请使用TestFlight下载最新版本!", confirmMessagePanel);
                }
            }
            else
            {
                //Utils.ShowConfirmMessagePanel("没有新版本", confirmMessagePanel);
                AutoLogin();
            }
        };

        ResponseHandle errorHandler = delegate(string error) {
            Debug.Log("errorHandler is called");
            Utils.HideMessagePanel(messagePanel);
            Utils.ShowConfirmMessagePanel("连接服务器失败,请检查你的网络", confirmMessagePanel);
        };

        var req = new {
            platform   = Utils.GetPlatform(),
            version    = Application.version,
            clientInfo = Utils.GetClientInfo(),
            userInfo   = Utils.GetUserInfo()
        };

        StartCoroutine(ServerUtils.PostRequest(ServerUtils.CheckUpdateUrl(), JsonConvert.SerializeObject(req), handler, errorHandler));
    }