I am using PhoneGap 1.1.0 and iOS 5.0, and have struggled on FileWriter problem.
Here’s the full example of http://docs.phonegap.com/en/1.1.0/phonegap_file_file.md.html#FileWriter
does work fine.
Creating a FileWriter from the onDeviceReady works.
However, since what I want to do is to create a FileWriter depending on
various filenames on demand, I did as follows:
(function ($){
document.addEventListener("deviceready", function ()
{
var FSroot;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onInitFs, errorHandler);
function onInitFs(fs)
{
FSroot = fs.root;
//.......
}
//.......
function writeFile(myText1)
{
var filename = "namedProgramatically";
alert("CHECK1");
FSroot.getFile(filename, {create: true}, gotFileEntry, fail);
function gotFileEntry(fileEntry)
{
alert("CHECK2");
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer)
{
writer.onwrite = function(evt)
{alert("WRITE Done!!");};
writer.write(myText1);
}
function fail(error)
{
alert(error.code);
}
}
//...........
}); //========================
})(jQuery)
This code does not work.
I see “CHECK1” alert, but not “CHECK2”.
I have no clue, what is wrong?
Please give me some advice.
Thank you.
Ken
(edit)
The problem may be a JavaScript-JQuery scope issue although I’m not sure.
I have re-developed a FileWrite unit test code on iOS5.0+ PhoneGap1.1.0 + JQuery1.7, and finally it works as I intended.
Here is the full working code.(my Google Docs link)
https://docs.google.com/document/pub?id=1B58qVbIldDQ6s_WbPiCwB9MDnXxqlidUBbwQxNP2geg
The problem may be a JavaScript-JQuery scope issue although I’m not sure. I have re-developed a FileWrite unit test code on iOS5.0+ PhoneGap1.1.0 + JQuery1.7, and finally it works as I intended. Here is the full working code.(my Google Docs link)
https://docs.google.com/document/pub?id=1B58qVbIldDQ6s_WbPiCwB9MDnXxqlidUBbwQxNP2geg