应用升级方案

此方案只是针对使用我们内部的应用商城的情况。若放到其他商城请自行参考各自提供的sdk.

1、首先在工程的application.xml文件中修改项目的版本信息。
QQ截图20151215150213.png

2、在项目首页的onload方法中对当前版本和商城中的所放应用的版本的版本信息进行对比。

示例代码

  1. function viewload() {
  2. //检查版本是否需要更新
  3. $service.post({
  4. "url" : "http://store.yyuap.com/mobas/app/appdetail", //appstore提供的获取应用版本信息的固定url地址
  5. "data" : {
  6. appid : "mtscm"//appid是与商城确定一个唯一的id
  7. },
  8. "callback" : "checkUpdateCallBack()",
  9. "timeout" : "5"
  10. });
  11. }
  12. function checkUpdateCallBack() {
  13. var result = $stringToJSON($ctx.param("result"));
  14. if (!result) {
  15. return;
  16. }
  17. var data = $stringToJSON(result.data);
  18. if (!data) {
  19. return;
  20. }
  21. if (!data.appdetail) {
  22. return;
  23. }
  24. var appdetail = $stringToJSON(data.appdetail);
  25. if (!appdetail) {
  26. return;
  27. }
  28. var version = $ctx.getApp("versionName");
  29. //判断当前设备是否是IOS设备
  30. if (CurrentEnvironment.DeviceType == CurrentEnvironment.DeviceIOS) {
  31. var newversion = appdetail.iosversion;
  32. if (newversion != version) {
  33. if (confirm("发现新版本,需要更新吗?")) {
  34. $device.openWebView({
  35. url : appdetail.iosqrcodepath
  36. });
  37. }
  38. }
  39. }
  40. //判断当前设备是否是Android设备
  41. if (CurrentEnvironment.DeviceType == CurrentEnvironment.DeviceAndroid) {
  42. var newversion = appdetail.androidversion;
  43. if (newversion != version) {
  44. if (confirm("发现新版本,需要更新吗?")) {
  45. $device.openWebView({
  46. url : appdetail.androidqrcodepath
  47. });
  48. }
  49. }
  50. }
  51. }
文档更新时间: 2018-01-15 14:54