Cordova Cross-platform app version upgrade

Source: Internet
Author: User

Use Cordova+ionic to develop a good project, followed by a package release, before that, you have to do a version of the upgrade of the small features.

First of all, there is no natural configuration in the root directory of our project: CONFIG.

。 Version, we will read the version field from this wiget tag every time we upgrade the app.

Cordova has provided the app version get plugin tool, cordova-plugin-appversion

Gets the version number of the local app via the plugin and gets the version number of the background by request. and then compare.

function Onready () {        cordova.getAppVersion.getVersionNumber (). Then (function (version) {        });        Popup.waitload (' Checking for updatable versions ');        Commonapi.getupgradeversioninfo (function (res) {          if (!res.success) {            throw new Error ("Get App version number information failed" + ( Res.retinfo? Res.retinfo: ""));          }          Popup.hideloading ();          var appversion = res.data.dataObject.serverVersion;          var upgradeinfo = Res.data.dataObject.upgradeInfo;          var url = res.data.dataObject.updateUrl;          Console.log ("Platform is iOS:" + ionic. Platform.isios ());          Gets the current app version information          if (compareversion (version,appversion)) {            showupdateconfirm (upgradeinfo, URL, appversion);          } else {            popup.promptmsg (' No new version available ', ' Update Hint ')}        }, {versionflag:versionflag});      }}    ;

comparison function

Compareversion (version,appversion), front and back conventions, version numbers use the "semantic version". such as x.y.z. The front and rear tables are separated by two points using three numbers.
/** Compare version number * @param localversion local app version number * @param newversion Server return version number * @returns {Boolean}*/    functioncompareversion (localversion, newversion) {Console.log ("New version%s-old version%s", NewVersion, localversion); if(typeofLocalversion = = = ' String ' &&typeofNewVersion = = = ' String '){          varLocalversionarray = Localversion.split ('. ')); varNewversionarray = Newversion.split ('. ')); if(Localversionarray.length = = =newversionarray.length) {               for(vari = 0; i < localversionarray.length; i++){                if(parseint (Newversionarray[i]) >parseint (Localversionarray[i])) {                  return true; }Else if(parseint (Newversionarray[i]) >parseint (Localversionarray[i])) {                  return false; }Else {                  Continue; }              }              return false; }Else{popup.loadmsg (' Version number record error ', 500,function () {                  return;          }); }      }Else{popup.loadmsg (' Version number record error ', 500,function () {            return;      }); }    }

After the version comparison, there is a new version in the browser to jump to the specified address download.

Cordova Cross-platform app version upgrade

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.