document.addEventListener('plusready', function() {
var first = null;
document.addEventListener("netchange",onNetChange,false);
function onNetChange(){
//獲取當前網絡類型
var nt = plus.networkinfo.getCurrentType();
switch(nt){
case plus.networkinfo.CONNECTION_ETHERNET:
case plus.networkinfo.CONNECTION_WIFI:
mui.toast("網絡已連接");
break;
default:
mui.toast("網絡已斷開");
break;
}
}
var webview = plus.webview.currentWebview();
plus.key.addEventListener('backbutton', function() {
document.addEventListener("netchange",onNetChange,false);
webview.canBack(function(e) {
if (e.canBack) {
webview.back();
} else {
if (!first) {
first = new Date().getTime();
mui.toast('再按一次退出應用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
}
})
});
// plus對象 升級
if(plus) {
var btn = ["確定升級", "取消"];
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
ver = inf.version;
console.log(ver)
ajaxurl = "http://xxxxxxxx";//後端地址
$.ajax({
url: ajaxurl+'/common/version',
success: function(data) {
console.log(data)
console.log(data.result.version )
if (data.result.version != ver) {
var _msg = "當前版本:V" + ver+",最新版本號:V"+data.result.version;
// var _msg = "當前版本:V" + data.result.version;
mui.confirm(_msg, '升級確認', btn, function(e) {
if (e.index == 0) { //執行升級操作
plus.nativeUI.showWaiting( "正在準備環境,請耐心等候!" );
var dtask = plus.downloader.createDownload(data.result.downloadURL, {
}, function(d, status) {
if (status == 200) {
var path = d.filename; //下載apk
plus.runtime.install(path); // 自動安裝apk文件
plus.nativeUI.closeWaiting(); //下載好之後,showwait消失
} else {
plus.nativeUI.alert('版本更新失敗:' + status);
}
});
dtask.start();
}
});
} else {
mui.toast('當前版本號已是最新');
return;
}
},
error: function(xhr, type, errerThrown) {
mui.toast('網絡異常,請稍候再試');
}
});
});
}
});