应用升级
12147安卓应用升级
- web端读取_constant表中version的信息
// web端读取_constant表中version的信息
async versionCheck() {
setTimeout(async () => {
await this.versionCheck();
}, 10000);
const versionConstantKey = 'version';
let data;
data = (
await window.jianghuAxios({
data: {
appData: {
pageId: 'allPage',
actionId: 'getConstantList'
}
}
})
).data.appData.resultData;
const {rows: constantList} = data;
localStorage.setItem('constantsArray', JSON.stringify(constantList));
const serverVersionMap = constantList.find(item => item.constantKey === versionConstantKey);
const serverVersion = JSON.parse(serverVersionMap.constantValue);
window.serverVersion = serverVersion;
},
// 获取版本号
function getServerVersion() {
if (window.serverVersion) {
return JSON.stringify(window.serverVersion);
}
}
- APP端,每15秒读取version信息
//代码来源:/jianghuAppBrowser/jianghuBrowser/lib/Utils/LocalStorageUtil.dart
static Future<void> looperGetServerVersion(BuildContext context, String _runningPage) async {
if(Constants.appId.value == 'browser' && Constants.isLoginPage) {
return;
}
if(RenderKey.controller.value == null) {
return;
}
if (WebViewHandler().complete) {
String serverVersion = await RenderKey.controller.value!.runJavascriptReturningResult("getServerVersion()");
if (serverVersion != "null" && serverVersion != "(null)") {
try {
Map<String, dynamic> versionMap = Utils.replaceAllJsonString(serverVersion);
Constants.serverVersion = ServerVersionEntity.fromJson(versionMap);
Constants.webVersion = Constants.serverVersion.version;
if (Platform.isAndroid) {
VersionUtil.updateApp(context);
}
} catch (error) {
print("localStorage serverVersion error: $error");
}
}
}
if(_runningPage == runningPage) {
Future.delayed(const Duration(seconds: 15), () async {
looperGetServerVersion(context, _runningPage);
});
}
}
- 下载并安装app
参考:
/jianghuAppBrowser/jianghuBrowser/lib/Utils/VersionUtil.dart
流程:updateApp -> checkNeedUpdate -> downloadApk -> updateDialogRunUpdateBtn -> downloadImpl -> downloadFile -> installApk