Create directories and files in IOS using IONIC framework

1

I need to run a sort of CRUD in directories and files through an IOS application.

This application uses the IONIC framework, which in turn uses Cordova and AngularJS features.

The questions are:

  • Regarding permissions, does the IOS system allow this kind of functionality?
  • If yes, through what exactly is it possible to create these files and directories? (AngularJS, Javascript "pure", Cordova, or even libs like Jquery, etc.).
  • How can I create, read, modify, and delete these files and directories?
asked by anonymous 16.04.2016 / 23:49

1 answer

1

It is possible by using the window.requestFileSystem method, which is native to Cordova. Do not forget to add the read / write permission for files in your configuration file. For iOs, edit your config.xml file by adding these lines:

<feature name="File">
    <param name="ios-package" value="CDVFile" />
</feature>
<feature name="FileTransfer">
    <param name="ios-package" value="CDVFileTransfer" />
</feature>

And below is an example of how to use the requestFileSystem, to open the foor folder and create the bar.txt file

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
   fileSystem.root.getDirectory("foo", {create: true}, gotDir);
}

function gotDir(dirEntry) {
    dirEntry.getFile("bar.txt", {create: true, exclusive: true}, gotFile);
}

function gotFile(fileEntry) {
    // manipule o arquivo aqui da forma que você quiser
}
    
17.04.2016 / 00:58