Storing and updating config files

ChrisNurseChrisNurse AUMember ✭✭

Hi everyone, I've recently ported a MIDI music app from PC to iOS with a good deal of success so far. I need to maintain compatibility between data files, for example, imagine I have an XML file which I use on iOS and PC which describes a piece of music. I want this file to be installed with the app when it runs. I also want to save changes to this file on the local device when the app exits.

An easy way to imagine this scenario is think of user settings being stored in an XML file. I don't want the file to start life blank, so I provide a default set of settings to the app for when it starts. Then when the app exits, it needs to update these settings for next time.

I've set the BuildAction on my file to BundleResource, and also set the Copy to Output Folder, both which seem to be required to get the file into the right place, (I want to store all this stuff in a sub directory called DataFiles).

So all is well on the Emulator, my settings are loaded and saved. However, on the actual iOS device, the file loads OK, but I can't write to it, I get an UnauthorizedAccessException when I try to write back to the file.

I have all sorts of theories as to what's going on, but no idea how to fix it :) For example, is it because I've selected to have these files copied in to place as BundleResources,and as such they're not expected to be modifiable?

Any thoughts and sample code / patterns would be really appreciated, as I'm very stuck! :(

Thanks,
Chris

Tagged:

Posts

  • Taimoor.JanjuaTaimoor.Janjua DEMember ✭✭

    Hi @ChrisNurse

    • You can't write to bundle directory, because it's code signed with ssl certificate, so you can't break that.
    • You can write to documents folder of your app for persistance, as every app is an Island I.e. you are limited to the directories in your app's sandbox.

      var DocDirectoy = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
      var NewDirectory = Path.Combine (DocDirectoy, "NewDirectory");
      Directory.CreateDirectory(NewDirectory);

      var SettingsFile = Path.Combine (NewDirectory, "Settings.xml");
      XmlDocument xml = new XmlDocument();
      xml.save(SettingsFile);

    Hope it helps

    Kind Regards,
    Taimoor Janjua

Sign In or Register to comment.