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