標籤:錯誤 安裝 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升級檢查