我最終通過進入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;
}
};
}]);
如果有多個下載會發生什麼? –