4

I am integrating a cocos2d-js game into a native iOS app.

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

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

But my project.json is in Document folder instead of in my bundle. So 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 having an idea how I should implement SomeFunctionToGetPath?

Thanks for your help.

jiglesiasf
  • 61
  • 4

1 Answers1

0

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

This is one way you could do it in your 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"));
0xDEADBEEF
  • 83
  • 5