应用升级方案
此方案只是针对使用我们内部的应用商城的情况。若放到其他商城请自行参考各自提供的sdk.
1、首先在工程的application.xml文件中修改项目的版本信息。
2、在项目首页的onload方法中对当前版本和商城中的所放应用的版本的版本信息进行对比。
示例代码
function viewload() {
//检查版本是否需要更新
$service.post({
"url" : "http://store.yyuap.com/mobas/app/appdetail", //appstore提供的获取应用版本信息的固定url地址
"data" : {
appid : "mtscm"//appid是与商城确定一个唯一的id
},
"callback" : "checkUpdateCallBack()",
"timeout" : "5"
});
}
function checkUpdateCallBack() {
var result = $stringToJSON($ctx.param("result"));
if (!result) {
return;
}
var data = $stringToJSON(result.data);
if (!data) {
return;
}
if (!data.appdetail) {
return;
}
var appdetail = $stringToJSON(data.appdetail);
if (!appdetail) {
return;
}
var version = $ctx.getApp("versionName");
//判断当前设备是否是IOS设备
if (CurrentEnvironment.DeviceType == CurrentEnvironment.DeviceIOS) {
var newversion = appdetail.iosversion;
if (newversion != version) {
if (confirm("发现新版本,需要更新吗?")) {
$device.openWebView({
url : appdetail.iosqrcodepath
});
}
}
}
//判断当前设备是否是Android设备
if (CurrentEnvironment.DeviceType == CurrentEnvironment.DeviceAndroid) {
var newversion = appdetail.androidversion;
if (newversion != version) {
if (confirm("发现新版本,需要更新吗?")) {
$device.openWebView({
url : appdetail.androidqrcodepath
});
}
}
}
}
文档更新时间: 2018-01-15 14:54