fir.im官方文档:fir.im - 免费应用内测托管平台|iOS应用Beta测试分发|Android应用内测分发 (betaqr.com)https://www.betaqr.com/docs
1.获取本地app版本
// 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid, (info) => {
console.log(JSON.stringify(info)); //本地应用信息
this.version = info.version.replace(/\./g,'')
this.versionCode = info.versionCode
})
version一般是1.0.0、1.0.1,比较难直接比较,本文使用replace(/\./g,'')将‘.’去掉,直接比较100和101,如有bug恳请大家在评论区告诉我,谢谢!
2.利用fir.im查询最新app
uni.request({
//url参数外的{{}}要去掉,只保留参数即可,id和api_token在fir里可以查
url:'http://api.bq04.com/apps/latest/{{id}}?api_token={{api_token}}'
}).then(res=>{
let data = res[1].data
if(data.versionShort.replace(/\./g,'')>this.version || data.version>this.versionCode){
//fir上有新版本,执行下载方法,可根据自身情况添加确认框等
//执行3.下载和安装
}
else{
this.$u.toast('已经是最新版本!')
}
})
附:id和api_token查询位置
3.下载和安装(Android)
//第一步 获取 download_token
uni.request({
url:'http://api.bq04.com/apps/{{id}}/download_token?api_token={{api_token}}'
}).then(res=>{
//第二步 下载
var downloadTask = uni.downloadFile({
url: 'http://download.bq04.com/apps/{{id}}/install?download_token='+res[1].data.download_token,
success: (res) => {
console.log(res)
this.u = res.tempFilePath
},
fail: (res) =>{
console.log(res)
}
})
//监听下载进度
downloadTask.onProgressUpdate((res) => {
if(res.progress>=100){
uni.hideLoading();
//第三步 安装
plus.runtime.install(this.u)
}
});
})
uni.downloadFile 是uniapp官方给的下载方法,具体文档查阅uniapp官网