How to load xml settings file in iOS?

I set up settings in setup() with:

gui.setup("Parameters", (ofxiPhoneGetDocumentsDirectory() + "settings.xml"));

…and I’m trying to load them with:

gui.loadFromFile(ofxiPhoneGetDocumentsDirectory() + "settings.xml");

but getting:

[ error ] ofXml: couldn’t load, “settings.xml” not found
[warning] ofXml: setTo(): empty document

anything I could check?

Did you try [ ofXmlSettings ] ?

ofXmlSettings xmlsettings;
xmlsettings.load(ofxiPhoneGetDocumentsDirectory() + "settings.xml");

How about manual loading your “settings.xml” and inserting value to your gui componenets manually, if you can read by this way.

hey thanks for your reply. I probably should’ve posted on the beginner’s section, since I’m fairly new to OF.

Also, I should’ve been more specific. I’m trying to save settings from a ofxPanel, so that right after I set up the panel:

gui.setup("Parameters", "settings.xml");

I then start adding components and initial settings:

gui.add(countX.setup("countX", 50, 0, 200));

Now, as far as I can see, ofxPanel.cpp outlines the ofxPanel::setup method as:

ofxPanel * ofxPanel::setup(const std::string& collectionName, const std::string& filename, float x, float y)

which means to me that it expects a file it will use to save settings. I then use the ofxBaseGui::loadFromFile method to try to load the settings that have been saved at exit() whenever the iOS app starts again, when I call it from setup() as:

gui.loadFromFile(ofxiPhoneGetDocumentsDirectory() + "settings.xml");

but I get the error described above. As far as I can see, the ofxXmlSettings module will save any settings you push to it manually, but isn’t ofxPanel expecting me to use the default method to save panel settings? Here’s the whole setup() function:

void ImageApp::setup() {
    ofxXmlSettings settings;
    // initialise sound level
    //soundLevel = 0;
    //ofSoundStreamSetup(0, 1, 44100, 512, 1);
    showGui = true;
    //    ofSetWindowTitle( "Video synth" );
    //    ofSetWindowShape( 1280, 720 );
    ofSetFrameRate( 60 );
    ofBackground( ofColor::white );
    gui.setup("Parameters", "settings.xml");
    gui.add(countX.setup("countX", 50, 0, 200));
    gui.add(stepX.setup("stepX", 20, 0, 200));
    gui.add(twistX.setup("twistX", 5, -45, 45));
    // matrix controls
    gui.add(countY.setup("countY", 0, 0, 50));
    gui.add(stepY.setup("stepY", 20, 0, 200));
    gui.add(twistY.setup("twistY", 0, -30, 30));
    gui.add(pinchY.setup("pinchY", 0, 0, 1));
    // set up control groups
    // primitives control group
    primGroup.add(filled.setup("filled", false));
    primGroup.add(type.setup("type", false));
    // load last saved setup
    gui.loadFromFile(ofxiPhoneGetDocumentsDirectory() + "settings.xml");


Hi again.

I know why can’t save that your GUI settings.

Because “ofFileUtils.cpp”. exactly It used “ofToDataPath()”, this is not direction to “ofxiPhoneGetDocumentsDirectory()”.

Simply, You can change like this for fix your problem rapidly

//line 439 form "ofFileUtils.cpp"
bool ofFile::open(const std::filesystem::path & _path, Mode _mode, bool binary){
	//Disable this line and change to next line. It didn't using "ofToDataPath". 
	//myFile = std::filesystem::path(ofToDataPath(_path.string()));
	myFile = std::filesystem::path(_path.string());
	return openStream(_mode, binary);

It was work in my case. (I was checked.)

But! ofFileUtils is very commons class. if you change like this, you should check side effects.

So , I recommendation was manually save and load works for GUI settings with [ofXmlSettings]