美文网首页
uniApp自动更新版本

uniApp自动更新版本

作者: 花影_62b4 | 来源:发表于2021-04-30 14:35 被阅读0次

App.vue

<script>

import interfaces from "utils/api.js"

export default {

onLaunch: function() {

console.log('App Launch')

this.getNewVersion();

},

onShow: function() {

console.log('App Show')

},

onHide: function() {

console.log('App Hide')

},

globalData: {

requestUrl: "http://xxxxxxx",

userInfo: null,

timer: null

},

methods: {

getNewVersion() {

let self = this;

this.http({

url: interfaces.getNewVersion,

showLoading: false,

callback: (res) => {

console.log(res.data)

let newVersion = res.data.Data;

plus.runtime.getProperty(plus.runtime.appid, function(inf) {

console.log(inf)

if (Number(inf.versionCode) < newVersion.VersionCode) {

uni.showModal({

content: '检测到新版本,是否更新?',

success: showResult => {

if (showResult.confirm) {

let url=newVersion.Domain+newVersion.Url;

var dtask = plus.downloader.createDownload(url, {},

function(d, status) {

// 下载完成 

if (status == 200) {

plus.runtime.install(plus.io.convertLocalFileSystemURL(

d.filename

), {}, {},

function(error) {

uni.showToast({

title: '安装失败',

mask: false,

duration: 1500

});

})

} else {

uni.showToast({

title: '更新失败',

mask: false,

duration: 1500

});

}

});

dtask.start();

}

}

});

}

});

}

})

}

}

}

</script>

<style>

/*每个页面公共css */

</style>

相关文章

网友评论

      本文标题:uniApp自动更新版本

      本文链接:https://www.haomeiwen.com/subject/chvnrltx.html