IONIC 自动更新APP版本
IONIC 自动更新APP版本
源自http://blog.csdn.net/dailuwen/article/details/49887607,非常感谢戴子的分享,为方便查阅,记录中自己的博客。
1、准备工作,添加插件
如果cordova 未添加请先执行以下命令 1、npm install bower -g //安装bower 2、bower install ngCordova //安装cordova
1.1、添加获取APP版本信息插件
ionic plugin add cordova-plugin-app-version
2.2、添加APP自动更新相关插件
ionic plugin add cordova-plugin-file ionic plugin add cordova-plugin-file-transfer ionic plugin add cordova-plugin-file-opener2
2、在APP一运行的时候就进行检查版本信息(在run方法添加如下代码)
.run(function($ionicPlatform, $http, $rootScope, $ionicActionSheet, $timeout, $cordovaAppVersion, $ionicPopup, $ionicLoading, $cordovaFileTransfer, $cordovaFile, $cordovaFileOpener2) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); }; if (window.StatusBar) { StatusBar.styleDefault(); }; //服务器上保存版本信息 $http.get('http://localhost/app/ver.json') .then(function(data){ var serverAppVersion = data.data.verInfo;//服务器 版本 console.log("====>>服务器"+serverAppVersion); $cordovaAppVersion.getVersionNumber().then(function(version) { console.log("version=====本机>>>"+version+"====>>服务器"+serverAppVersion); if (version != serverAppVersion) { $ionicLoading.show({ template: "已经下载:0%" }); var url = "http://192.168.1.77:8080/app/android-debug.apk"; var targetPath = "file:///mnt/sdcard/Download/android-debug.apk"; var trustHosts = true var options = {}; $cordovaFileTransfer.download(url, targetPath, options, trustHosts).then(function (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; $ionicLoading.show({ template: "已经下载:" + Math.floor(downloadProgress) + "%" }); if (downloadProgress > 99) { $ionicLoading.hide(); } }) }); } }); }); }); })
3、在服务端webapp下添加以下两个文件
1、ver.json 2、Android-debug.apk
相关推荐
绿豆饼 2020-07-28
kfq00 2020-04-10
shichong 2015-05-14
samllcat 2019-07-01
Android进阶 2019-07-01
liujia 2019-07-01
MonkeyKingBi 2019-06-29
wangdazhu0 2019-06-28
liujia 2019-06-28
芯果科技蔡彦 2016-08-25
半纸药笺 2020-07-26
半纸药笺 2020-06-14
芯果科技蔡彦 2020-04-30
芯果科技蔡彦 2020-04-14
samllcat 2020-03-27
ZillahV0 2016-08-27
半纸药笺 2019-11-18
qixiang0 2015-04-24