原文:cordova APP 检查更新

//升级程序
.factory('UpdateService', function ($rootScope, $cordovaAppVersion, $cordovaFileTransfer, $timeout, $ionicLoading, $cordovaFileOpener2, $http, $ionicPopup, xc) { //检查更新
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('从服务器获取数据失败!');
})
.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.update.url;
showUpdateConfirm(url, data.info || '');
}
}
);
});
}; /**
*
* @param url
* @param info
*/
var showUpdateConfirm = function (url, info) { var confirmPopup = $ionicPopup.confirm({
title: '版本升级',
template: info.toString().replace(/\n/g, '<br />'),
cancelText: '取消',
okText: '升级'
}); confirmPopup.then(function (res) {
if (res) {
$rootScope.process = 0;
$ionicLoading.show({
template: '<ion-spinner icon="bubbles" class="spinner-assertive spinner spinner-bubbles"></ion-spinner><br>已经下载:{{process}}%'
});
var targetPath = cordova.file.externalDataDirectory + "update.apk";//APP下载存放的路径,可以使用cordova file插件进行相关配置
var trustHosts = true;
var options = {};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts).then(function (result) {
// 打开下载下来的APP //console.log(JSON.stringify(result)); $cordovaFileOpener2.open(targetPath, 'application/vnd.android.package-archive'
).then(function () { }, function (err) { });
$ionicLoading.hide();
}, function (err) {
alert('下载失败');
}, function (progress) {
//进度,这里使用文字显示下载百分比
$timeout(function () {
var downloadProgress = (progress.loaded / progress.total) * 100;
$rootScope.process = Math.floor(downloadProgress);
if (downloadProgress > 99) {
$ionicLoading.hide();
}
})
}); } else {
// 取消更新
}
});
}; return {
checkUpdate: checkUpdate
}
})

  

最新文章

  1. android之volley学习
  2. Ubuntu换源
  3. The system cannot find the file specified
  4. git clone
  5. LinkedList源码分析
  6. Asp.Net Web API 2第十五课——Model Validation(模型验证)
  7. 你已经毁了JavaScript
  8. 【winform】如何在DateTimePicker中显示时分秒
  9. ES6 之 let和const命令 Symbol Promise对象
  10. 使用 Buildot 实现持续集成
  11. Tomcat8 + Redis实现session集中管理
  12. php的序列化和反序列化有什么好处?
  13. Hibernate问题浅析
  14. nginx.conf文件
  15. Windows10下配置python的环境变量
  16. 6.6 Pandora 实操 - API/SDK
  17. C实战:项目构建Make,Automake,CMake【转】
  18. 利用PHP扩展Taint找出网站的潜在安全漏洞实践
  19. SIFT特征点检测学习一(转载)
  20. Pycharm创建Django项目并访问Django

热门文章

  1. 作为一个新人,怎样学习嵌入式Linux?(韦东山)
  2. (转)linux screen 命令详解
  3. PyCharm下载主题以及个性化设置(详细)
  4. wepy小程序实现列表分页上拉加载(2)
  5. Spring 使用Cache(转)
  6. Eclipse高效开发插件汇总
  7. 关于Altium Designer的一些设置
  8. 将OpenCV捕获的摄像头加载到picture控件中
  9. embed-it_Integrator memory compile工具使用之二
  10. 看朋友日志发现的一个ios下block相关的内存管理问题,非常奇怪,请大家帮忙一起来回答!