Files
youfang-app/fangija-zsyf/js/updateVersion/updateVersion.js
T
hubingliang 34f4cb9dee xcx下载
2018-03-16 13:20:51 +08:00

85 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var versionUpdate = function(){
var isAndroid = isAndroidUser();
alert("变成安卓了")
  plus.runtime.getProperty(plus.runtime.appid, function(inf) {
inf.version;
localVersion =inf.version;
var isNeed = needUpdate(inf.version);
if(isNeed){
alert("有房有了新版本了,不更新就无法愉快的玩耍了");
if(isAndroid){
downApp()
}else{
plus.nativeUI.showWaiting("版本更新中...");
var url='https://itunes.apple.com/cn/app/id1341557643?mt=8';// HelloH5应用在appstore的地址
plus.runtime.openURL(url);
}
}
});
};
var isAndroidUser = function(){
var osName = plus.os.name;
var isAndroid = true;
if(osName=="Android") {
isAndroid= true;
}else{
isAndroid= false;
}
return isAndroid;
}
//判断是否需要安装
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);
});
}