Cordoba / Phonegap - iOSExtraFilesystems iOS user root path does not work

I am using cordova 3.4 with the org.apache.cordova.file file on iOS (latest version 1.3.1).

I want to store data in the Library / NoCloud directory, I found that in the document we have to set these variables in the config.xml file:

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

But it does not work, it gives me the root file system in the library / files, and I cannot go to the NoCloud directory, because we cannot get the parent element of the root library / files.

Is someone also struggling with this problem? Have you used iosExtraFilesystems var successfully?

I am trying to update a cordova, but I have other problems when doing this. I will post further progress.

UPDATE:

Does not work with cordova 3.5, 3.6 either, I created a problem on jira tracker apache: https://issues.apache.org/jira/browse/CB-7687

thanks

Tibo

+6
source share
2 answers

Use resolveLocalFileSystemURL, not requestLocalFileSystem

The easiest way to do this (starting with v1.2.0) is via the cordova.file.dataDirectory property. This should be the path to the library-nosync directory. You can use it in combination with resolveLocalFileSystemURL to get a directory entry object into which you can create files.

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 parameters that you indicated in your question:

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

This preference simply tells the File plugin that, by default, the PERSISTENT file system should store files in the device’s Library directory. Without this setting, the default location used by previous versions of Cordoba, the Documents directory, is used. Regardless of the fact that the library file system is available for your application (if you have not disabled it with the following setting)

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

Preference iosExtraFilesystems tells the File plan to which the root file system belongs, in addition to the default settings (temporary and permanent) for the installation. By default, it is set to string

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

This already includes library-nosync , so you do not need to add it. In fact, installing it the way you really removed the other filesystem roots from your application.

+11
source

All credits for this answer are sent to Wei Li: https://github.com/weili-feedhenry/dotfiles/issues/1 , and you should read his post about the cordova file system plugin: http://web.archive.org/ web / 20160731021013 / http: //www.feedhenry.com/several-ways-avoid-problems-cordova-file-api-mobile-apps

Obviously, the API API file is not updated, in order to get the desired file system, you need to change the request file system type in the requestFileSystem request. For instance:

 window.requestFileSystem(3, 0, function(fs){ alert("dataDirectory = " + cordova.file.dataDirectory); alert("root = " + fs.root.toURL()); fs.root.getFile("test.txt", {create: true, exclusive: true}); }, function(){ alert("failed to get file system") }); 

note that the file system type in the above call is β€œ3” - if you added the following settings to the config.xml file:

If you change the value of iosExtraFilesystems, you may need to adjust the value of the request type accordingly.

0
source

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


All Articles