//獲取版本號提示更新 var btn = ["確定升級", "取消"]; //獲取app系統更新[是否手動點擊獲取更新] function appUpdate(ismanual) { console.log('appUpdate'); var banbenid=1; mui.plusReady(function () { plus.runtime.getProperty(plus.runtime.appid, function (inf) { ver = inf.version; console.log('手機版本ver:' + ver); var client; var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test(ua)) { //蘋果手機 mui.ajax(url+"/front_get_bybneben.do?id="+banbenid,{ type: "GET", async:false, dataType: "jsonp", success: function (data) { //console.log('data:' + JSON.stringify(data)); var resultCount = data.list.banben; //console.log(resultCount); if (resultCount > ver) { var _msg = "發現新版本:V" + resultCount; //plus.nativeUI.alert("發現新版本:V" + normItem); mui.confirm(_msg, '升級確認', btn, function (e) { if (e.index == 0) { //執行升級操作 document.location.href = 'http://******/HibuddyApp.apk'; //上新APPStore下載地址 }else if(e.index == 1){ plus.runtime.quit(); } }); return; } if (ismanual) { mui.toast('當前版本號已是最新'); } return; } }); } else if (/android/.test(ua)) { mui.ajax(url+"/front_get_bybneben.do?id="+banbenid,{ type: "GET", async:false, dataType: "jsonp", success: function (data) { // console.log('data:' + JSON.stringify(data)); var json_data = jQuery.parseJSON(data); var resultCount = json_data.list.banben; console.log(resultCount); /* if (resultCount > ver) { var _msg = "發現新版本:V" + resultCount; //plus.nativeUI.alert("發現新版本:V" + normItem); mui.confirm(_msg, '升級確認', btn, function (e) { if (e.index == 0) { //執行升級操作 document.location.href = 'http://*****/HibuddyApp.apk'; //上新APPStore下載地址 }else if(e.index == 1){ plus.runtime.quit(); } }); return; } if (ismanual) { mui.toast('當前版本號已是最新'); } return; },*/ var apkUrl = "http://114*****uddy/HibuddyApp.apk"; if (resultCount > ver) { //mui.toast("發現新版本:V" + data.Data);//獲取遠程數據庫中上新andriod版本號 var _msg="發現新版本:V" + resultCount; mui.confirm(_msg, '升級確認', btn, function (e) { if (e.index == 0) { //執行升級操作 plus.nativeUI.toast("正在准備環境,請稍后!"); var dtask = plus.downloader.createDownload(apkUrl, {}, function (d, status) { if (status == 200) { var path = d.filename;//下載apk plus.runtime.install(path); // 自動安裝apk文件 } else { plus.nativeUI.alert('版本更新失敗:' + status); } }); dtask.start(); }else if(e.index == 1){ plus.runtime.quit(); } }); } else { console.log('當前版本號已是最新'); if (ismanual) { mui.toast('當前版本號已是最新'); } return; } }, error: function (xhr, type, errerThrown) { if (ismanual) { mui.toast('網絡異常,請稍候再試'); } } }); } }); }); }
ajax訪問的是從后台數據庫傳來的一個版本號(這個版本號是開發者自己手動輸入上去)每次升級,需要自己改動版本號
而手機上的版本號是開發者平台打包時,配置的必填項;
需要在數據庫見一個存放版本號的表
查詢出來的版本號與手機版本號相對比