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