1. 程式人生 > >app 版本升級

app 版本升級

adfs haier function get ips ava urn javascrip 信息

cordova plugin add cordova-plugin-appversion //獲取當前版本號

cordova plugin add cordova-plugin-file-transfer  //下載

  

判斷平臺

          判斷平臺
      let vm = this let browser = { versions: function () { let u = navigator.userAgent, app = navigator.appVersion; return {//移動終端瀏覽器版本信息 trident: u.indexOf(‘Trident‘) > -1, //IE內核 presto: u.indexOf(‘Presto‘) > -1, //opera內核 webKit: u.indexOf(‘AppleWebKit‘) > -1, //蘋果、谷歌內核 gecko: u.indexOf(‘Gecko‘) > -1 && u.indexOf(‘KHTML‘) == -1, //火狐內核 mobile: !!u.match(/AppleWebKit.*Mobile/i) || !!u.match(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/), //是否為移動終端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios終端 android: u.indexOf(‘Android‘) > -1 || u.indexOf(‘Linux‘) > -1, //android終端或者uc瀏覽器 iPhone: u.indexOf(‘iPhone‘) > -1 || u.indexOf(‘Mac‘) > -1, //是否為iPhone或者QQHD瀏覽器 iPad: u.indexOf(‘iPad‘) > -1, //是否iPad webApp: u.indexOf(‘Safari‘) == -1 //是否web應該程序,沒有頭部與底部 }; } (), language: (navigator.browserLanguage || navigator.language).toLowerCase() } if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios ) { vm.platform = 1 } if (browser.versions.android) { vm.platform = 2 } //platform ==1 ios平臺,2安卓平臺

如果是ios,直接跳到蘋果商店相應的位置就好

安卓

let vm = this
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
          let url = ‘url‘;
          fs.root.getFile(‘userApp.apk‘, {create: true, exclusive: false},
            function (fileEntry) {
              download(fileEntry.toURL(), url);
            }, onErrorCreateFile);
        }, onErrorLoadFs);
        function download(fileEntry, url) {
          let ft = new FileTransfer();
          let fileURL = fileEntry;
          ft.onprogress = function (e) {
        //獲取進度
            if (e.lengthComputable) {
              vm.percentShow = true
        //進度e.loaded / e.total
           vm.$set(vm.percent,‘num‘,parseInt( e.loaded / e.total * 100, 10)) 
const colorMap = [‘#FFA55E‘]
vm.$set(vm.percent,‘strokeColor2‘,colorMap[parseInt( e.loaded / e.total * 3, 10)])
}
}
ft.download(url, fileURL, function (entry) {
cordova.plugins.fileOpener2.open( fileEntry, ‘application/vnd.android.package-archive‘, {
error : function(e) {
console.log(‘Error status: ‘ + e.status + ‘ - Error message: ‘ + e.message);
}, success : function () { console.log(‘file opened successfully‘);
}
} );
}, function (err) {
alert("下載失敗!:"+JSON.stringify(err));
}, null, // or, pass false
{
//headers: {
// "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
//} });
}
//文件創建失敗回調
function onErrorCreateFile(error) {
alert("文件創建失敗!")
}
//FileSystem加載失敗回調
function onErrorLoadFs(error) {
alert("文件系統加載失敗!")
}

  

app 版本升級