uni-app android 整包更新 版本号获取问题(已解决调试包覆盖不了)
uni-app android 整包更新 版本号获取问题(已解决调试包覆盖不了)
| 项目信息 | 详情 |
|---|---|
| 产品分类 | uniapp/App |
| PC开发环境 | Windows |
| PC开发环境版本 | 20H2 |
| HBuilderX类型 | Alpha |
| HBuilderX版本 | 3.2.1 |
| 手机系统 | Android |
| 手机系统版本 | Android 10 |
| 手机厂商 | 华为 |
| 手机机型 | 荣耀v30pro |
| 页面类型 | vue |
| 打包方式 | 云端 |
| 项目创建方式 | HBuilderX |
操作步骤:
android整包更新版本
plus.runtime.getProperty获取版本号不正确
预期结果:
plus.runtime.getProperty 获取当前apk版本号
实际结果:
获取之前的版本号
bug描述:
android 整包更新 从1.0.0更新到1.0.3
通过下面的方法获取当前版本号
plus.runtime.getProperty(plus.runtime.appid, inf => {
console.log(inf);
this.$store.commit('config/SET_VERSION', inf.version);
this.$store.commit('config/SET_VERSIONNUMBER', inf.versionCode);
});
inf.version 为1.0.0 和 inf.versionCode 为 100
而通过plus.runtime.versionCode 获取的是 1.0.3 ,实际查看手机应用里面的版本号的确是升级为1.0.3
更多关于uni-app android 整包更新 版本号获取问题(已解决调试包覆盖不了)的实战教程也可以访问 https://www.itying.com/category-93-b0.html
你好,请问是如何解决的?
更多关于uni-app android 整包更新 版本号获取问题(已解决调试包覆盖不了)的实战教程也可以访问 https://www.itying.com/category-93-b0.html
不要用调试包,调试包不能升级
回复 1***@qq.com: 没有理解,什么叫,调试包不能升级?我现在遇到的问题是,我打了测试基座,然后发现,升级的时候,覆盖升级总是容易新代码没有生效。然后功能还是旧的,但是卸载了本地的,再安装,都是可以的。就直接覆盖安装容易翻车。这是什么回事呢
回复 史蒂芬丿闰土: 自定义基座无法覆盖,打正式包才行
回复 1***@qq.com: 好的, 谢谢,我还以为是什么鬼问题。
这是一个典型的整包更新后版本信息缓存问题。plus.runtime.getProperty 获取的是应用安装时的原始版本信息,而 plus.runtime.version 和 plus.runtime.versionCode 获取的是当前运行版本的实际信息。
解决方案:
在整包更新场景下,应直接使用 plus.runtime.version 和 plus.runtime.versionCode 来获取当前版本号,而不是通过 getProperty 回调。
修改你的代码为:
// 获取当前版本信息
let currentVersion = plus.runtime.version;
let currentVersionCode = plus.runtime.versionCode;
console.log('当前版本:', currentVersion);
console.log('当前版本号:', currentVersionCode);
this.$store.commit('config/SET_VERSION', currentVersion);
this.$store.commit('config/SET_VERSIONNUMBER', currentVersionCode);

