| | |
| | | { |
| | | try |
| | | { |
| | | var requestObj = new ForceUpdateObj() |
| | | { |
| | | LanguageType = Utlis.GetPostLanguageType() |
| | | }; |
| | | #if __IOS__ |
| | | requestObj.DeviceType = PhoneDeviceType.IOS.ToString(); |
| | | #endif |
| | | var requestJson = HttpUtil.GetSignRequestJson(requestObj); |
| | | var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_CheckAppVersion, requestJson); |
| | | var revertObj = new HttpServerRequest().CheckAppVersion(); |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | { |
| | | var mForceUpdateInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ForceUpdateInfo>(revertObj.Data.ToString()); |
| | | if (mForceUpdateInfo != null) |
| | | if (revertObj.Data != null) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | var appVersionRes = Newtonsoft.Json.JsonConvert.DeserializeObject<AppVersionRes>(revertObj.Data.ToString()); |
| | | if (appVersionRes != null) |
| | | { |
| | | ShowForceUpdateDialog(mForceUpdateInfo); |
| | | }); |
| | | |
| | | var mForceUpdateInfo = new UpdateDialogInfo() |
| | | { |
| | | UpdateType = appVersionRes.isEnforce ? 2 : 1, |
| | | NewVersion = appVersionRes.version, |
| | | NewVersionUrl = appVersionRes.androidUrl |
| | | }; |
| | | #if __IOS__ |
| | | mForceUpdateInfo.NewVersionUrl = appVersionRes.iosUrl; |
| | | #endif |
| | | //解析更新内容详情 |
| | | var reasonStrJson = GetReasonStrJson(appVersionRes.updateDescription); |
| | | if (reasonStrJson != null) |
| | | { |
| | | if (Language.CurrentLanguage == "Chinese") |
| | | { |
| | | mForceUpdateInfo.ReasonStr = reasonStrJson.Chinese; |
| | | } |
| | | else |
| | | { |
| | | mForceUpdateInfo.ReasonStr = reasonStrJson.English; |
| | | } |
| | | } |
| | | |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | ShowForceUpdateDialog(mForceUpdateInfo); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="jsonStr"></param> |
| | | /// <returns></returns> |
| | | public ReasonStrJson GetReasonStrJson(string jsonStr) |
| | | { |
| | | try |
| | | { |
| | | if (!string.IsNullOrEmpty(jsonStr)) |
| | | { |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<ReasonStrJson>(jsonStr); |
| | | } |
| | | return null; |
| | | } |
| | | catch |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 提示强制更新Dialog |
| | | /// 点击确认跳转浏览器 |
| | | /// </summary> |
| | | public void ShowForceUpdateDialog(ForceUpdateInfo mForceUpdateInfo) |
| | | public void ShowForceUpdateDialog(UpdateDialogInfo mUpdateDialogInfo) |
| | | { |
| | | // 1.1 没有更新 返回 |
| | | if (mForceUpdateInfo.UpdateType == 0) return; |
| | | if (mUpdateDialogInfo.UpdateType == 0) return; |
| | | // 1.2 有新版本但是忽略过 返回 |
| | | if (mForceUpdateInfo.UpdateType == 1 && (UserInfo.Current.IgnoreUpdateVersion == mForceUpdateInfo.NewVersion)) return; |
| | | if (mUpdateDialogInfo.UpdateType == 1 && (UserInfo.Current.IgnoreUpdateVersion == mUpdateDialogInfo.NewVersion)) return; |
| | | // 2.1 有新版本没有忽略过 提示更新 |
| | | if (mForceUpdateInfo.UpdateType == 1) |
| | | if (mUpdateDialogInfo.UpdateType == 1) |
| | | { |
| | | Action okAction = () => |
| | | { |
| | | if (string.IsNullOrEmpty(mForceUpdateInfo.NewVersionUrl)) return; |
| | | if (string.IsNullOrEmpty(mUpdateDialogInfo.NewVersionUrl)) return; |
| | | |
| | | HDLUtils.OpenUrl(mForceUpdateInfo.NewVersionUrl); |
| | | HDLUtils.OpenUrl(mUpdateDialogInfo.NewVersionUrl); |
| | | }; |
| | | |
| | | Action cancelAction = () => |
| | | { |
| | | //UserInfo.Current.IgnoreUpdateVersion = mForceUpdateInfo.NewVersion; |
| | | //UserInfo.Current.SaveUserInfo(); |
| | | UserInfo.Current.IgnoreUpdateVersion = mUpdateDialogInfo.NewVersion; |
| | | UserInfo.Current.SaveUserInfo(); |
| | | }; |
| | | |
| | | //1提示更新 |
| | | var dialog = new UpdateTipDialog(); |
| | | var tipStr = Language.StringByID(StringId.VersionNumber) + mForceUpdateInfo.NewVersion; |
| | | dialog.ShowUpdateDialog(Language.StringByID(StringId.DiscoverNewVersion), tipStr, mForceUpdateInfo.ReasonStr, okAction, cancelAction); |
| | | var dialog = new UpdateTipDialog(); |
| | | var tipStr = Language.StringByID(StringId.VersionNumber) + mUpdateDialogInfo.NewVersion; |
| | | dialog.ShowUpdateDialog(Language.StringByID(StringId.DiscoverNewVersion), tipStr, mUpdateDialogInfo.ReasonStr, okAction, cancelAction); |
| | | |
| | | } |
| | | else if (mForceUpdateInfo.UpdateType == 2) //2.2 需要强制更新 |
| | | else if (mUpdateDialogInfo.UpdateType == 2) //2.2 需要强制更新 |
| | | { |
| | | //2强制更新 |
| | | //"1.发现新版本App,当前版本已停用,马上更新!\n2.请下载和安装新版本!....." |
| | | Action okAction = () => |
| | | { |
| | | if (string.IsNullOrEmpty(mForceUpdateInfo.NewVersionUrl)) { |
| | | if (string.IsNullOrEmpty(mUpdateDialogInfo.NewVersionUrl)) |
| | | { |
| | | Utlis.ShowTip(Language.StringByID(StringId.DataExceptionPleaseTryAgain)); |
| | | return; |
| | | }; |
| | | |
| | | HDLUtils.OpenUrl(mForceUpdateInfo.NewVersionUrl); |
| | | HDLUtils.OpenUrl(mUpdateDialogInfo.NewVersionUrl); |
| | | }; |
| | | |
| | | |
| | | //1提示更新 |
| | | var dialog = new UpdateTipDialog(); |
| | | var tipStr = Language.StringByID(StringId.VersionNumber) + mForceUpdateInfo.NewVersion; |
| | | dialog.ShowForcedUpdateDialog(Language.StringByID(StringId.DiscoverNewVersion), tipStr, mForceUpdateInfo.ReasonStr, okAction); |
| | | var tipStr = Language.StringByID(StringId.VersionNumber) + mUpdateDialogInfo.NewVersion; |
| | | dialog.ShowForcedUpdateDialog(Language.StringByID(StringId.DiscoverNewVersion), tipStr, mUpdateDialogInfo.ReasonStr, okAction); |
| | | } |
| | | else //3. 只需提示 |
| | | { |
| | | //3提示通知 |
| | | Action okAction = () => |
| | | { |
| | | |
| | | |
| | | }; |
| | | var dialog = new UpdateTipDialog(); |
| | | dialog.ShowTipDialog(Language.StringByID(StringId.Tip), mForceUpdateInfo.ReasonStr, okAction); |
| | | dialog.ShowTipDialog(Language.StringByID(StringId.Tip), mUpdateDialogInfo.ReasonStr, okAction); |
| | | } |
| | | } |
| | | |