首先安裝插件android
cordova plugin add cordova-plugin-file-transferios
代碼ide
function downLoad(url) { document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { hmsPopup.showLoading('loading'); var fileTransfer = new FileTransfer(); var fileURL; if(navigator.platform == 'iPhone'){ fileURL = cordova.file.documentsDirectory+"1535075145153.xlsx"; }else{ fileURL = cordova.file.externalRootDirectory+"1535075145153.xlsx"; } fileTransfer.download( url, fileURL, function(entry) { hmsPopup.hideLoading(); vm.localUrl = entry.toURL(); // alert("本地路徑"+vm.localUrl); // alert("localUrl"+vm.localUrl); dict.params.attachmentPath = vm.localUrl; // alert("dict.params.attachmentPath"+dict.params.attachmentPath); HandBridge.postMessage(JSON.stringify(dict)); }, function(error) { hmsPopup.hideLoading(); console.log("download error source " + error.source); console.log("download error target " + error.target); console.log("download error code" + error.code); }, false, { // headers: { // "Authorization": 'Bearer' + " " + StorageService.getStorage("access_token") // } } ); } }
增長監聽事件post
因爲android和ios手機的基礎路徑不一樣,因此經過下面代碼判斷android和ios的機型,在肯定基礎路徑url