After our app development is completed, it is inevitable that the product will be upgraded in the future, so we hope that the app will be automatically upgraded on the customer's mobile phone, which can be divided into automatic upgrade and manual upgrade.
Automatic upgrade: usually when the customer app opens the homepage for the first time.
Manual upgrade: Provide an upgrade entrance in the app interface.
The interface effect is demonstrated as follows:
The code is actually very simple, but it needs to be processed separately for ios and android. The basic idea is to obtain the app version number of the local machine, and then compare it with the app version number on the server. If it is less than the app version number on the server, then perform an update operation.
var btn = [Confirm upgrade, cancel];//Get app system update [Whether to manually click to get the update] function appUpdate(ismanual) { console.log('appUpdate'); mui.plusReady(function () { plus.runtime. getProperty(plus.runtime.appid, function (inf) { ver = inf.version; console.log('ver:' + ver); var url = config.GetAppVersion; var client; var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test(ua)) { //Apple phone mui.ajax({ type: get, dataType: 'json', url: https://itunes.apple.com/lookup?id=1318127518,//Get the currently available APPStore version information data: { id: 131812xxxx //APP unique identification ID }, contentType: 'application/x-www-form-urlencoded;charset=UTF-8', success: function (data) { console.log('data:' + JSON.stringify(data) ); var resultCount = data.resultCount; for (var i = 0; i < resultCount; i++) { var normItem = data.results[i].version; console.log('normItem:' + normItem) if (normItem > ver) { var _msg = New version found: V + normItem; //plus.nativeUI.alert(New version found: V + normItem); mui.confirm( _msg, 'Upgrade confirmation', btn, function (e) { if (e.index == 0) { //Perform upgrade operation document.location.href = 'https://itunes.apple.com/cn/app/san-gu-hui/id131812xxxx?mt=8'; //New APPStore download address} }); return; } } if (ismanual) { mui. toast('The current version number is the latest'); } return; } }); } else if (/android/.test(ua)) { mui.ajax(url, { data: { apkVersion: ver, }, dataType: 'json', type: 'get', timeout: 10000, success: function (data) { //console.log('data:'+JSON.stringify(data)) if ( data.StatusCode = 200 && data.Data > ver) { //mui.toast(New version found: V + data.Data);//Get the new andriod version number in the remote database var _msg=New version found: V + data.Data; mui.confirm(_msg, 'Upgrade confirmation', btn, function (e) { if (e .index == 0) { //Perform the upgrade operation plus.nativeUI.toast (preparing the environment, please wait! ); var dtask = plus.downloader.createDownload(config.apkUrl, {}, function (d, status) { if (status == 200) { var path = d.filename;//Download apk plus.runtime.install( path); // Automatically install apk file } else { plus.nativeUI.alert('Version update failed:' + status); } }); dtask.start(); } }); } else { console.log('The current version number is already the latest'); if (ismanual) { mui.toast('The current version number is the latest'); } return; } }, error: function (xhr, type, errerThrown) { if (ismanual) { mui.toast('Network abnormality, please try again later'); } } }); } }); });}Our ios applications are published in the Apple App Store, while android applications are deployed directly on our own servers (such as IIS servers), because there are too many android application markets, so every time the version is upgraded, it will be the same. A very troublesome thing is that every time you release a version, you have to go to all Android application markets to submit updates.
It should be noted that when calling this method using manual update and automatic update, different parameters must be passed in, because in automatic update, if the system detects that the current version is already the latest version, it will not be displayed on the client, and manual update If it is already the latest version, then the customer needs to be reminded.
Automatic update call: appUpdate();//Detect app updates
Manual update call: appUpdate(true);//Detect app updates
The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope everyone will support VeVb Wulin Network.