Cordova APP Check for updates

Source: Internet
Author: User

Upgrade program. Factory (' Updateservice ', function ($rootScope, $cordovaAppVersion, $cordovaFileTransfer, $timeout, $            Ionicloading, $cordovaFileOpener 2, $http, $ionicPopup, XC) {//check update var checkupdate = function () { $cordovaAppVersion. GetVersionNumber (). Then (function (v) {var url = xc.server.domain + ' update/checknew/                ' + xc.app.id + '/android/' + V;                    $http. Get (URL). Error (function () {Console.log (' failed to get data from server! ');                            }). Then (function (response) {var data = Response.data;                            var compatible_binary = data.compatible_binary;                            var update_available = data.update_available; if (compatible_binary && update_available) {var url = xc.server.domain + DATA.UPDA                                Te.url; Showupdateconfirm (URL, data.info||                            ‘‘);            }                        }                    );        });        };            /** * * @param URL * @param info */var showupdateconfirm = function (URL, info) { var confirmpopup = $ionicPopup. Confirm ({title: ' Version upgrade ', Template:info.toString ()            . replace (/\n/g, ' <br/> '), Canceltext: ' Cancel ', Oktext: ' Upgrade '});                    Confirmpopup.then (function (res) {if (res) {$rootScope. Process = 0; $ionicLoading. Show ({Template: ' <ion-spinner icon= "bubbles" class= "spinner-assertive spinner S                    Pinner-bubbles "></ion-spinner><br> already downloaded: {{process}}% '});                    var TargetPath = cordova.file.externalDataDirectory + "update.apk";//app download the stored path, which can be configured using the Cordova file plugin                    var trusthosts = true; VAr options = {}; $cordovaFileTransfer. Download (URL, TargetPath, Options, trusthosts). Then (function (Result) {//Open under                        Downloaded app//console.log (json.stringify (result));                         $cordovaFileOpener 2.open (TargetPath, ' application/vnd.android.package-archive '). Then (function () {                        }, function (Err) {});                    $ionicLoading. Hide ();                    }, function (ERR) {alert (' download failed ');                            }, function (progress) {//progress, use text to display the download percentage $timeout (function () {                            var downloadprogress = (progress.loaded/progress.total) * 100;                            $rootScope. Process = Math.floor (downloadprogress);                     if (DownloadProgress > ©) {$ionicLoading. Hide ();       }                        })                    });        } else {//Cancel update}});        }; return {checkupdate:checkupdate}})

  

Cordova APP Check for updates

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.