Where should apps store persistent files (eg, CoreData persistent store files)?
Apple's doco has always said to use the 'Documents' directory, however in iOS 4 this directory is exposed to the user for read/write file sharing through iTunes for apps that enable it.
Apple's doco explicitly recommends against storing files directly in 'Library/Preferences'.
So where are our apps supposed to store our files if we want to enable the file sharing, but do not want users to clobber important persistent files?
Should we be creating additional directories under 'Library'? Eg, 'Library/Data', or 'Library/Application Support'?
I appears that the application support directory does not exist, but the constant and function exist to get a string for its path making it easy to create in a consistent location is a way that 'feels' like it's supported. Therefore the following works just fine for me in testing so far:
Does this "Library/Application Support" directory seem like a reasonable place to store persistent files that should not be directly accessible by the user while also using iOS 4 file sharing through iTunes (to the Documents directory).
Surely other people have got solutions to this? Anyone care to share?
I'm not sure about the Application Support directory, but I've been creating a hidden directory in the Documents directory in iPad apps that have file sharing enabled. Remember you only need to worry about this if you're going to be using the sharing function and have it enabled - otherwise you can just use the Documents directory like normal.
Basically on launch I check to see if my hidden directory is there, if it isn't I make it and use that for any persistent files. Any directory that starts with a . will be hidden in iTunes (at least the Mac iTunes, not sure about Windows iTunes...) so I create something like Documents/.appfiles/MyApp.sqlite and that does the trick.
Sounds reasonable, assuming it remains hidden in all situations including Windows. I guess there's a possibility (exceedingly remote) that the user could still clobber the files by copying in something with the same name.
It's really odd that Apple have done this in such a way that forces us to use kludge work arounds and don't appear to have any real solution documented.
One minute they're telling us to use the Documents directory for all our app data and the next thing they're exposing this directory to end users for file sharing without providing any recomended alternatives to app developers who are coming up with a variety of inconsistent and kludgy work arounds.
Sounds reasonable, assuming it remains hidden in all situations including Windows. I guess there's a possibility (exceedingly remote) that the user could still clobber the files by copying in something with the same name.
It's really odd that Apple have done this in such a way that forces us to use kludge work arounds and don't appear to have any real solution documented.
One minute they're telling us to use the Documents directory for all our app data and the next thing they're exposing this directory to end users for file sharing without providing any recomended alternatives to app developers who are coming up with a variety of inconsistent and kludgy work arounds.
I agree. I am working on an iPad app with file sharing enabled and I also persist data to a file which was previously located in the Documents directory. I am now using the '.folder' workaround but as was previously pointed out, this may not hide it on Windows which isn't satisfactory. Why couldn't Apple have just put an 'Files' folder inside of Documents which was made accessible to the public?
I can confirm that .directories/files are hidden in the Windows version of iTunes as well as the Mac version. I do agree it is sort of a hack workaround, but it does work.
Last time I looked, file sharing allowed reading from subdirectories, but not writing. Files sharing writes only allowed writing to the root of the Documents folder. Has this changed?