onLoad(){
this.plusReady();
this.isandroid();
},
methods: {
// 获取当前版本号
plusReady(){
var that = this;
// 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid,function(inf){
that.wgtVer = inf.version; //获取当前版本号
that.version = plus.runtime.version; //获取当前版本号 简写
});
},
// 检查是否安卓
isandroid(){
var that = this;
uni.getSystemInfo({
success:(res) => {
if(res.platform=="android"){
that.AndroidCheckUpdate();
}
}
})
},
// 自动更新
AndroidCheckUpdate(){
var that=this;
uni.request({
url: helper.webUrl + 'index.php/App/getAndroidVersion', //获取最新版本号
method: 'GET',
data: {},
success: res => {
if(res.data.version!=that.version){
if(plus.networkinfo.getCurrentType()!=3){
uni.showToast({
title: '有新的版本发布,检测到您目前非Wifi连接,为节约您的流量,程序已停止自动更新,将在您连接WIFI之后重新检测更新。',
mask: false,
duration: 5000,
icon:"none"
});
return;
}
uni.showToast({
title: '有新的版本发布,检测到您目前为Wifi连接,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
mask: false,
duration: 5000,
icon:"none"
});
//res.data.androidurl 是apk的下载链接
var dtask = plus.downloader.createDownload(res.data.androidurl, {}, 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();
}
}
});
},