Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova / Phonegap - iOS Filesystem custom root path iosExtraFilesystems is not working

I'm using cordova 3.4 with the org.apache.cordova.file on iOS (last version 1.3.1).

I want to store data in the Library/NoCloud directory, i've found that in the doc we should set this variables in config.xml :

<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosExtraFilesystems" value="library-nosync" />

But it's not working, it gives me a filesystem root in Library/files , and i can't move to the NoCloud directory because we can't get the parent of the root Library/files.

Is someone struggling with this issue as well ? Have you successfully used the iosExtraFilesystems var ?

I'm trying to upgrade cordova but i have other issues when doing it.. i will post further progress.

UPDATE:

Not working with cordova 3.5, 3.6 either, i've created an issue on the jira tracker of apache: https://issues.apache.org/jira/browse/CB-7687

Thanks

Thibault

like image 933
tdurand Avatar asked Oct 01 '14 22:10

tdurand


1 Answers

Use resolveLocalFileSystemURL rather than requestLocalFileSystem

The easiest way to do this (since v1.2.0) is with the cordova.file.dataDirectory property. It should be a path to the library-nosync directory. You can use it in conjunction with resolveLocalFileSystemURL to get a directory entry object that you can create files in.

Something like this should work:

resolveLocalFileSystemURL(cordova.file.dataDirectory, function(entry) {
    console.log("Success! Got a DirectoryEntry");
    // Do more things with `entry` here
}, function(error) {
    console.error("Something bad happened, and we didn't get a DirectoryEntry");
});

Some other notes

To clarify the two settings that you mentioned in your question:

<preference name="iosPersistentFileLocation" value="Library" />

This preference just tells the File plugin that, by default, the PERSISTENT file system should store files under the device's Library directory. Without that setting, the default is the location used by previous Cordova versions, the Documents directory. Regardless, the Library filesystem is available to your application (as long as you haven't disabled it with the next setting)

<preference name="iosExtraFilesystems" value="library-nosync" />

The iosExtraFilesystems preference tells the File plugin which file system roots, in addition to the defaults (temporary and persistent,) to install. By default, it is set to the string

"library,library-nosync,documents,documents-nosync,cache,bundle,root"

This already includes library-nosync, so you shouldn't have to add it. In fact, setting it the way you did actually removes the other file system roots from your application.

like image 175
Ian Clelland Avatar answered Nov 14 '22 22:11

Ian Clelland