我创建了一个正在下载mp4文件的移动应用程序(使用ionic / cordova)。我让它在android中运行,但在iOS中没有运气。奇怪的是,它有时会起作用,有时它不起作用(仅在iOS中)。我使用插件cordova-plugin-file-transfer
,当它工作时,它完美地工作。但是当我提醒错误时,我得到以下内容:
无法创建保存下载文件的路径:您没有hvae保存文件的权限
错误代码:1
以下是我的以下代码:
$scope.download = function(){
var downloadProgress ='';
var url = "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_5mb.mp4";
var MyFiles = cordova.file.dataDirectory + 'test1.mp4';
$cordovaFileTransfer.download(url,MyFiles,{}, true).then(
function(result){//success download
$ionicLoading.hide();
var alertPopup = $ionicPopup.alert({
title: 'Download Successful!',
});
}, function(error){
var alertPopup = $ionicPopup.alert({
title: 'Error',
template: JSON.stringify(error)
});
}, function(progress){
$timeout(function () {
downloadProgress = (progress.loaded / progress.total) * 100;
});
$ionicLoading.show({
template: 'Download in progress please wait<br/><progress id="progressbar" max="100" value="'+ downloadProgress +'"> </progress>' +
'<div id="progressbarlabel">' + Math.ceil(downloadProgress) + '%</div>'
});
});
}
答案 0 :(得分:0)
我尝试在iOS中使用cordova.file.documentsDirectory
:
if (ionic.Platform.isIPad() || ionic.Platform.isIOS()) {
console.log("Is iPad or iOS");
$rootScope.TARGETPATH = cordova.file.documentsDirectory;;
}
模拟器中的结果非常好,但是当我尝试使用真实设备时,我得到了:
您无权将文件“Documents”保存在“MY-APP-ID-XXXXXX”文件夹中。
所以,我尝试了cordova.file.dataDirectory
:
if (ionic.Platform.isIPad() || ionic.Platform.isIOS()) {
console.log("Is iPad or iOS");
$rootScope.TARGETPATH = cordova.file.dataDirectory;;
}