How to get document folder in ios device from Javascript

I integrate cocos2d-js into my native iOS application.

At some point, I have a Javascript function inside my ios application with the following code:

var txt = jsb.fileUtils.getStringFromFile("project.json"); 

But my project.json is in the Document folder, not in my package. Therefore, I need to get my document folder path in this Javascript file to have something like this:

 var myPath = SomeFunctionToGetPath(); var txt = jsb.fileUtils.getStringFromFile("myPath/project.json"); 

Anyone with an idea how I should implement SomeFunctionToGetPath ?

Thank you for your help.

+5
source share
1 answer

jsb.fileUtils.getWritablePath() returns the path to the Documents folder on iOS.

This is one way to do this in code:

 // First, define the function. var getFilePath = function(fileName) { return jsb.fileUtils.getWritablePath() + fileName; } // Then, call it when you need it. var txt = jsb.fileUtils.getStringFromFile(getFilePath("project.json")); 
-1
source

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


All Articles