Failed to write telephone file

Using the methods found in phonegap api I am trying to write a file. This works on Android, but on the iOS device, the author returns an error. Whenever I call writeFile (), it returns an error, and the parameter passed to writeFail is -1. I do not understand why -1 is passed to the error function or why it does not even start. Has anyone else used fileWriter on an iOS device or can you see what I can do wrong?

function writeFile() {
    var paths = navigator.fileMgr.getRootPaths();
    var writer = new FileWriter(paths[0] + "write.txt");
    writer.onwrite = writeSuccess;
    writer.onerror = writeFail;

    writer.write("some sample text");
    // The file is now 'some sample text'
}

function writeSuccess() {
    console.log("Write has succeeded");
}

function writeFail(evt) {
    console.log(evt);
    console.log(evt.target.error.code);
}
+3
source share
2 answers

I had the same problem, but I scanned the mailing list and finally found a solution:

var writer = new FileWriter("write.txt");

. "" -path. ( ).

"readAsDataURL", ( iOS). , .

+2

, (phonegap 2.5)

function fileWrite(filePath, text) {
  var onFSWin = function(fileSystem) {
    fileSystem.root.getFile(filePath, {create: true, exclusive: false}, onGetFileWin, onFSFail);
  }
  var onGetFileWin = function(fileEntry) {
    fileEntry.createWriter(gotFileWriter, onFSFail);
  }
  var gotFileWriter = function(writer) {
    writer.write(text);
  }
  var onFSFail = function(error) {
   console.log(error.code);
  }
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSWin, onFSFail);
 }  
+2

Source: https://habr.com/ru/post/1794575/


All Articles