欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > uniapp 在线更新应用

uniapp 在线更新应用

2025/11/22 15:28:56 来源:https://blog.csdn.net/qq_37550440/article/details/126230632  浏览:    关键词:uniapp 在线更新应用

在线更新应用及进度条显示

1.比较现安装手机中的apk 与线上apk的版本

getVersion(){var newVersion=uni.getStorageSync("newVersion").split(".")var version=plus.runtime.version.split(".") // 获取手机安装的版本var versionNum="",newVersionNum=""for(var i=0;i<version.length;i++){versionNum+=version[i]}for(var i=0;i<newVersion.length;i++){newVersionNum+=newVersion[i]}if(versionNum<newVersionNum){this.chooseUpApp()}},

2.选择android的方式安装还是apple的testFligt方式安装

chooseUpApp(){uni.showModal({title: '提示',content: plus.os.name == 'Android'?'检测到有最新版本,是否下载!':'检测到有最新版本,是否去TestFlight下载!',success:(res)=> {if (res.confirm) {if(plus.os.name == 'Android'){this.isUpApp=truethis.upApp()}else{plus.runtime.launchApplication({ action:this.upUrl}, function(e) {uni.showToast({icon:"none",title:"请确认手机安装了TestFlight"})console.log('Open system default browser failed: ' + e.message);  });  }} else if (res.cancel) {console.log('用户点击取消');}}});},

3.安装apk,并显示进度条

upApp(){//下载APPvar downloadTask=uni.downloadFile({url:this.upUrl,complete(res){console.log(res)if(res.statusCode==200){plus.runtime.install(res.tempFilePath, {force: false}, (e) => {this.isUpApp=falseplus.runtime.restart();}, (e) => {console.log(e);this.isUpApp=falseuni.showToast({title: '安装升级包失败',icon: 'none'})});}}})this.progress=0// console.log(downloadTask)downloadTask.onProgressUpdate((res) => { //监听下载进度变化console.log(res)if(this.progress!=res.progress){this.progress=res.progress// console.log('下载进度' + res.progress);// console.log('已经下载的数据长度' + res.totalBytesWritten);// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);}// 测试条件,取消下载任务。});},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词