Create IOS directories and files using IONIC framework

Asked

Viewed 607 times

1

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

This application is based on the IONIC framework, which in turn uses Cordova and Angularjs resources.

Doubts are:

  • Regarding permissions, the IOS system allows this type of functionality?
  • If so, through what exactly is it possible to create these files and directories? (Angularjs, "pure" Javascript, Cordova, or even libs like Jquery, etc).
  • How to create, read, modify and delete these files and directories?

1 answer

1


It is possible using the window.requestFileSystem method, which is native to Cordova. Don’t forget to add the read/write permission to your configuration file. In the case of 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 using 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
}
  • 1

    +1, I will test the implementation and soon after return to mark the answer as correct. For the moment, thank you!

  • 1

    Ziron, I asked a second question related to these needs, but now back to cloud storage. If you find it interesting, this is the link: http://answall.com/questions/123842/synchronizr-archives-generated

Browser other questions tagged

You are not signed in. Login or sign up in order to post.