Files
youfang-app/fangija-zsyf/js/updateVersion/updateVersion.js
T
hubingliang 9faebe9283 版本更新
2018-03-16 14:55:10 +08:00

80 lines
2.0 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();
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
var localVersion =inf.version;
var curVersion = versionInfo();
if(parseFloat(localVersion)<curVersion.version){
plus.nativeUI.alert( curVersion.updateDesc,
function(){
if(isAndroid){
downApp()
}else{
plus.nativeUI.showWaiting("版本更新中...");
var url='https://itunes.apple.com/cn/app/id1341557643?mt=8';
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 versionInfo = function(){
var flag = null;
$.ajax({
type: "GET",
url:BASE_PATH+"/rest/version/info",
dataType:'json',
async : false,
success: function(data) {
if(data.status){
flag = data.data;
}
}
})
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);
});
}