混合APP更新政策:
Android版實作直接下載下傳apk安裝更新,Ios版實作跳轉到蘋果商店進行更新更新
僅貼關鍵代碼段:
if ($rootScope.platform == 'ios') {
console.log('通路appstore進行更新');
console.log(versionInfo.downloadUrl);
$window.open(versionInfo.downloadUrl);//跳轉到APP商店這樣即可
return
}
var targetPath = "/sdcard/Download/"+verisonInfo.versionId + ".apk"; //APP下載下傳存放的路徑,可以使用cordova file插件進行相關配置;
var trustHosts = true;
var options = {};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts).then(function (result) {
// 打開下載下傳下來的APP
$cordovaFileOpener2.open(
targetPath,
'application/vnd.android.package-archive').then(function () {
// 成功
console.log('存儲為:' + targetPath);
}, function (err) {
// 錯誤
console.log(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();
}
})
});
} else {
// 取消更新
}
注意!!!
APK的下載下傳存放路徑必須是sd卡内,如果放進應用内檔案路徑下,打開apk時,會報如下錯誤:解析程式包時出現問題.