ionic android升級檢查

來源:互聯網
上載者:User

標籤:錯誤   安裝   scope   title   開啟   res   math   url   ova   

https://www.cnblogs.com/zxj159/p/4421578.html

坑:

放到cordova.file.DataDirectory下載異常? 只好cordova.file.externalDataDirectory

代碼
        // 檢查更新        $scope.appUpdateCheck = function(init) {            var init = init || 0;            // appUpdateService.showUpdateConfirm({});            // return;            VersionService.get({ platform: ionic.Platform.platform() }, function(resp) {                // alert(JSON.stringify(resp))                if (resp.code == ‘000‘) {                    // alert(resp.data.version)                    // alert($cordovaAppVersion.getVersionNumber())                    // alert($cordovaAppVersion.getVersionCode())                    cordova.getAppVersion.getVersionNumber(function(version) {                        // alert(version)                        if (version == resp.data.version) {                            if (!init) {                                messageService.show(‘當前已是最新版本‘);                            }                            return;                        }                        $scope.hasNewVersion = 1;                        $scope.device_items[1].name = $sce.trustAsHtml(‘升級檢查<font style="color:#FD1F38"> - New!</font>‘);                        if (!init) {                            appUpdateService.showUpdateConfirm(resp.data);                        }                    });                } else {                    messageService.show(resp.msg);                }            });        }
 ; (function(angular) {    angular.module(‘mobile‘)        .factory(‘appUpdateService‘, [‘$cordovaFileTransfer‘, ‘$cordovaFileOpener2‘, ‘$ionicPopup‘, ‘$ionicLoading‘, ‘$timeout‘, ‘messageService‘,            function($cordovaFileTransfer, $cordovaFileOpener2, $ionicPopup, $ionicLoading, $timeout, messageService) {                // 顯示是否更新對話方塊                function showUpdateConfirm(versionInfo) {                    var versionInfo = versionInfo;                    var downloadUrl = versionInfo.url,                        updateLog = versionInfo.upgradeinfo,                        targetPath = ‘file:///storage/sdcard0/Download/XiaoShuTong.apk‘ //APP下載存放的路徑,可以使用cordova file外掛程式進行相關配置                    // TODO 測試資料                    // downloadUrl = ‘http://imtt.dd.qq.com/16891/006473EB7690D8B89DEBD9613BF9E40E.apk?fsname=com.tencent.mm_6.6.0_1200.apk‘                    // updateLog = ‘1. 更新模組升級<br>2. 修複1個bug<br>‘                    targetPath = cordova.file.externalDataDirectory + ‘XiaoShuTong.apk‘                    var confirmPopup = $ionicPopup.confirm({                        title: ‘版本升級‘,                        template: updateLog, //從服務端擷取更新的內容                        cancelText: ‘取消‘,                        okText: ‘升級‘                    });                    confirmPopup.then(function(res) {                        if (res) {                            // if (ionic.Platform.isIOS()) {                            //     // 提示進入 APP store                            //     messageService.show(‘請到App Store升級.‘);                            // }                            if (ionic.Platform.isAndroid() && downloadUrl != ‘‘) {                                $ionicLoading.show({                                    template: "已經下載:0%"                                });                                $cordovaFileTransfer.download(downloadUrl, targetPath, null, true).then(function(result) {                                    // 開啟下載下來的APP                                    $cordovaFileOpener2.open(targetPath, ‘application/vnd.android.package-archive‘).then(function() {                                        // 成功                                    }, function(err) {                                        // 錯誤                                        // alert(‘安裝檔案開啟失敗, 請嘗試手動安裝.‘);                                        messageService.show(‘安裝檔案開啟失敗, 請嘗試手動安裝.‘);                                    });                                    $ionicLoading.hide();                                }, function(error) {                                    $ionicLoading.hide();                                    // alert(JSON.stringify(error));                                    // messageService.show(JSON.stringify(error));                                    messageService.show(‘請設定應用檔案操作許可權, 然後重試.‘);                                }, function(progress) {                                    var downloadProgress = Math.floor((progress.loaded / progress.total) * 100);                                    if (downloadProgress > 0) {                                        $ionicLoading.show({                                            template: ‘已經下載:‘ + downloadProgress + ‘%‘                                        });                                    }                                    if (downloadProgress > 99) {                                        $ionicLoading.hide();                                    }                                });                            }                        } else {                            // 取消更新                            $ionicLoading.hide();                        }                    });                }                // return                return {                    showUpdateConfirm: showUpdateConfirm                }            }        ]); })(angular);

ionic android升級檢查

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.