我看到了多個解決方案如何訪問www文件夾中的文件,但沒有解決方案適用於我。我使用iOS模擬器在iOS下測試應用程序。
我想訪問www文件夾中的文件test.txt
。Phonegap - 如何訪問www文件夾中的文件?
我目前的解決辦法是這樣的:
var filePathURI = getPhoneGapPath() + "test.txt";
window.resolveLocalFileSystemURI(filePathURI, onResolveSuccess, onFail);
function getPhoneGapPath() {
'use strict';
var path = window.location.pathname;
var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
return phoneGapPath;
};
這種解決方案並不爲我工作。我收到errorCode = 2
錯誤,這顯然意味着FileError.SECURITY_ERR
。不過我嘗試着用resolveLocalFileSystemURI
我無法訪問這個文件。
信息:我嘗試以下filePathURI
:
- /Users/UserName/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/GUID/AppName.app/www/test.txt
- 文件:///Users/UserName/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/GUID/AppName.app/www/test.txt
誰能給我一個工作的解決方案?
與Ajax調用我能夠訪問該文件的內容,但我需要用「resolveLocalFileSystemURI」方法的「FileEnty」對象......我增加了功能,但我仍然得到安全錯誤.. 。它似乎真的沒有權限訪問該文件 –