67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
var versionUpdate = function(){
|
||
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
|
||
inf.version;
|
||
localVersion =inf.version;
|
||
var isNeed = needUpdate(inf.version);
|
||
alert(isNeed)
|
||
if(isNeed){
|
||
alert("有房有了新版本了,不更新就无法愉快的玩耍了");
|
||
downApp()
|
||
}
|
||
});
|
||
|
||
};
|
||
//判断是否需要安装
|
||
var needUpdate = function(localVersion){
|
||
var flag = true;
|
||
$.ajax({
|
||
type: "GET",
|
||
url:BASE_PATH+"/rest/version/info",
|
||
dataType:'json',
|
||
async : false,
|
||
success: function(data) {
|
||
if(data.status){
|
||
var cruVersion = data.data
|
||
if(parseFloat(localVersion)<cruVersion){
|
||
|
||
flag = true;
|
||
}else{
|
||
flag = false;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
})
|
||
return flag;
|
||
}
|
||
|
||
//下载后安装
|
||
var downApp =function(){
|
||
var url="http://app.fangjia.com/download/youfang.apk"; // 下载文件地址
|
||
plus.nativeUI.showWaiting("下载wgt文件...");
|
||
var dtask = plus.downloader.createDownload( url, {}, function ( d, status ) {
|
||
if ( status == 200 ) { // 下载成功
|
||
installWgt(d.filename)
|
||
} else {//下载失败
|
||
alert( "Download failed: " + status );
|
||
}
|
||
plus.nativeUI.closeWaiting()
|
||
});
|
||
dtask.start();
|
||
}
|
||
|
||
//安装
|
||
function installWgt(path){
|
||
plus.nativeUI.showWaiting("安装wgt文件...");
|
||
plus.runtime.install(path,{},function(){
|
||
plus.nativeUI.closeWaiting();
|
||
plus.nativeUI.alert("应用资源更新完成!",function(){
|
||
plus.runtime.restart();
|
||
});
|
||
},function(e){
|
||
plus.nativeUI.closeWaiting();
|
||
plus.nativeUI.alert("安装wgt文件失败["+e.code+"]:"+e.message);
|
||
});
|
||
} |