h5+ Hybrid mobile app development--app upgrade

Source: Internet
Author: User

When the development of our app is complete, there will inevitably be a product upgrade in the future, then we want to make the app automatic upgrade on the customer's mobile phone, can be divided into automatic upgrade and manual upgrade.

Auto-upgrade: Usually the first time the Customer app opens the homepage.

Manual upgrade: Provides an upgraded portal in the app interface.

The interface effect is shown below:

The code is also simple, but it's for iOS and Android to be processed separately. The basic idea is to get the app version number of the machine, and then compare it with the app version number on the server, if it is smaller than the app version number on the server, then perform the update operation.

varBTN = ["OK Upgrade", "Cancel"];//Get app system updates [whether to manually click Get updates]functionappupdate (ismanual) {Console.log (' Appupdate '); Mui.plusready (function() {Plus.runtime.getProperty (Plus.runtime.appid,function(INF) {ver=inf.version; Console.log (' Ver: ' +ver); varURL =CONFIG.            Getappversion; varclient; varUA =navigator.userAgent.toLowerCase (); if(/iphone|ipad|ipod/.test (UA)) {//Apple PhoneMui.ajax ({type:"Get", DataType:' JSON ', URL:"Https://itunes.apple.com/lookup?id=1318127518",//get the current listing AppStore version informationdata: {ID:131812xxxx//app unique identification ID}, ContentType:' Application/x-www-form-urlencoded;charset=utf-8 ', Success:function(data) {Console.log (' Data: ' +json.stringify (data)); varResultcount =Data.resultcount;  for(vari = 0; i < Resultcount; i++) {                            varNormitem =data.results[i].version; Console.log (' Normitem: ' +Normitem)if(Normitem >ver) {                                var_msg = "New version found: V" +Normitem; //Plus.nativeUI.alert ("Found new version: V" + normitem);Mui.confirm (_msg, ' Upgrade confirmation ', BTN,function(e) {if(E.index = = 0) {//Perform an upgrade operationDocument.location.href = ' https://itunes.apple.com/cn/app/san-gu-hui/id131812xxxx?mt=8 ';//the new AppStore                                    }                                }); return; }                         }                        if(ismanual) {mui.toast (' Current version number is up to date '); }                        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 = && data. Data >ver) {                            //Mui.toast ("Discover new version: V" + data.) Data);//Get the new Andriod version number in the remote database                            var_msg= "Found new version: V" +data.                            Data; Mui.confirm (_msg,' Upgrade confirmation ', BTN,function(e) {if(E.index = = 0) {//Perform an upgrade operationPlus.nativeUI.toast ("Preparing for the environment, please later!") "); varDtask = Plus.downloader.createDownload (Config.apkurl, {},function(d, status) {if(Status = = 200) {                                            varPath = D.filename;//Download apkPlus.runtime.install (path);//install apk files automatically}Else{Plus.nativeUI.alert (' Version update failed: ' +status);                                    }                                    });                                Dtask.start ();                        }                            }); } Else{Console.log (' Current version number is up to date '); if(ismanual) {mui.toast (' Current version number is up to date '); }                            return; }}, Error:function(XHR, type, errerthrown) {if(ismanual) {mui.toast (' Network exception, please try again later ');            }                    }                });    }        }); });}

Our iOS apps are published in the Apple App Store, and Android apps are deployed directly on our own servers (such as IIS servers), because Android app market is too much, so every upgrade is a very troublesome thing, when you publish a version, You have to go to all Android app markets to submit updates.

Note that this method is called with Manual update and automatic Update, to pass in different parameters, because if the system detects that the current version is currently up to date, it will not be displayed on the client, and if it is updated manually, the customer needs to be prompted.

Automatic Update call: Appupdate ();//Detect app Updates

Manual Update Call: Appupdate (TRUE);//Detect app Updates

h5+ Hybrid mobile app development--app upgrade

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.