我最终通过进入NG-cordova.js文件直接和添加abort函数像这样解决这个问题:
我做了一个叫工厂对象的内部英尺全局变量和删除变量实例在“下载”功能中,以使其对所有功能具有全局性。
/* globals FileTransfer: true */
angular.module('ngCordova.plugins.fileTransfer', [])
.factory('$cordovaFileTransfer', ['$q', '$timeout', function ($q, $timeout) {
var ft = new FileTransfer();
return {
download: function (source, filePath, options, trustAllHosts) {
var q = $q.defer();
var uri = (options && options.encodeURI === false) ? source : encodeURI(source);
if (options && options.timeout !== undefined && options.timeout !== null) {
$timeout(function() {
ft.abort();
}, options.timeout);
options.timeout = null;
}
ft.onprogress = function (progress) {
q.notify(progress);
};
q.promise.abort = function() {
ft.abort();
};
ft.download(uri, filePath, q.resolve, q.reject, trustAllHosts, options);
return q.promise;
},
upload: function (server, filePath, options, trustAllHosts) {
var q = $q.defer();
var uri = (options && options.encodeURI === false) ? server : encodeURI(server);
if (options && options.timeout !== undefined && options.timeout !== null) {
$timeout(function() {
ft.abort();
}, options.timeout);
options.timeout = null;
}
ft.onprogress = function (progress) {
q.notify(progress);
};
q.promise.abort = function() {
ft.abort();
};
ft.upload(filePath, uri, q.resolve, q.reject, options, trustAllHosts);
return q.promise;
},
/* Here is the added abort function that will
kill the download or upload by calling $cordovaFileTransfer.abort() */
abort: function() {
var q = $q.defer;
ft.abort();
q.resolve;
return q.promise;
}
};
}]);
如果有多个下载会发生什么? –