我正在開發一個iPhone應用程序,用戶可以在Xcode中使用PhoneGap和HTML下載文件(.pdf,.docx等),然後查看它們是否在線(),其中基本上用戶通過網站查看文件()或'離線'(),用戶已經預先下載了它們,現在正在下載什麼文件,並且可以從設備的LocalFileSystem中查看文件。我可以下載一個.txt文件。使用PhoneGap下載PDF以便離線觀看?
function downloadEditFile() {
var fileDownloadEdit = new FileTransfer();
var uri = encodeURI("http://dl.dropbox.com/u/97184921/editme.txt");
fileDownloadEdit.download(
uri,
pathToRoot + '/editme.txt',
function(entry) {
console.log("download complete: " + entry.fullPath);
alert("File Downloaded. Click 'Read Editable Downloaded File' to see text");
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
}
但是當我嘗試開發它下載一個.pdf文件時,它會中斷。我需要幫助,我在哪裏出錯?我真正所做的是將文件名更改爲Holidays.pdf
,但console
出來說,
2013-03-14 11:06:47.921 TestApp1[265:15b03] -[CDVFileTransfer download:] [Line 313] File Transfer downloading file...
2013-03-14 11:06:48.553 TestApp1[265:15b03] File Transfer Finished with response code 404
2013-03-14 11:06:48.553 TestApp1[265:15b03] -[CDVFileTransferDelegate connectionDidFinishLoading:] [Line 437] Write file /Users/administrator/Library/Application Support/iPhone Simulator/6.1/Applications/AF96D141-0CE5-4D60-9FA8-8A8F9A999C81/Documents/Holidays.pdf
2013-03-14 11:06:48.554 TestApp1[265:15b03] FileTransferError {
code = 3;
"http_status" = 404;
source = "http://dl.dropbox.com/u/97184921/Internship%2520Stuff/Holidays.pdf";
target = "/Users/administrator/Library/Application Support/iPhone Simulator/6.1/Applications/AF96D141-0CE5-4D60-9FA8-8A8F9A999C81/Documents/Holidays.pdf";
}
2013-03-14 11:06:48.556 TestApp1[265:15b03] [LOG] download error source http://dl.dropbox.com/u/97184921/Internship%2520Stuff/Holidays.pdf
2013-03-14 11:06:48.556 TestApp1[265:15b03] [LOG] download error target /Users/administrator/Library/Application Support/iPhone Simulator/6.1/Applications/AF96D141-0CE5-4D60-9FA8-8A8F9A999C81/Documents/Holidays.pdf
2013-03-14 11:06:48.557 TestApp1[265:15b03] [LOG] upload error code3
怎麼回事?我相當新的Xcode和PhoneGap所以任何幫助都將是偉大的:)
這裏是確切的JavaScript下載PDF文件;
function downloadPDFFile() {
var fileDownloadPDF = new FileTransfer();
var uri = encodeURI("http://dl.dropbox.com/u/97184921/Internship%20Stuff/Holidays.pdf");
fileDownloadPDF.download(
uri,
pathToRoot + '/Holidays.pdf',
function(entry) {
console.log("download complete: " + entry.fullPath);
alert("File Downloaded. Click 'Read Editable Downloaded File' to see text");
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
}
和我用來調用函數的HTML是;
<button onclick="downloadPDFFile();">Download PDF File</button> <br>
我收到FileTransfer未定義的錯誤。有沒有第三方庫,你正在使用這個或什麼? – 2014-01-16 04:08:05