我正在開發一個帶有Cordova 2.1.0的ios應用程序。Cordova/phonegap文件系統沒有準備好「deviceready」
即使「deviceready」事件觸發,fileSystem似乎也不可用。
window.onload = function(){
document.addEventListener("deviceready", getSettings(), false);
}
function getSettings(){
fileSys('settings.txt', 'getContent', null);
}
function fileSys(fileName, action, data){
alert('hello'); // fires
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
alert('hello'); // does not fire
//rest of the script breaks
}
請求文件系統後腳本中斷。但是,如果我將調用封裝到setTimeout中的fileSys(),它就可以工作。例如:
window.onload = function(){
document.addEventListener("deviceready", getSettings(), false);
}
function getSettings(){
setTimeout(function(){
fileSys('settings.txt', 'getContent', null);
}, 500);
}
function fileSys(fileName, action, data){
alert('hello'); // fires
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
alert('hello'); // fires
//script runs fine
}
對此的任何解決方案?
它也工作正常,如果我將超時設置爲0其實腳本運行完全正常的全部時間用的setTimeout。但我真的很想在發佈應用程序之前瞭解它的底部。任何線索? – Pjottur