5

I want the user to be able to access the files in the documents directory but am using core data and dont want the user to be able to access the store (the sqllite db), can i hide it from the user while still allowing file sharing, or can i put it in another directory where it will still get backed up?

Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228

2 Answers2

14

The answer given by FrenchKiss Dev is not correct. The user will still be able to see the ".data" directory in iTunes and save that locally with all the files inside it.

Instead, store private documents in Library/Preferences

According to Apple:

In addition to the directories documented previously, the entire /Library directory has always been preserved during updates and backups, except for /Library/Caches. Because of this, applications can create their own directories in /Library/ and those directories will be preserved in backups and across updates. To minimize the risk of name collisions, we recommend that you name this directory carefully. For example, a directory named Private Documents would be a good choice. You should store any files you don't want to share to Library/Preferences.

William Denniss
  • 16,089
  • 7
  • 81
  • 124
memmons
  • 40,222
  • 21
  • 149
  • 183
  • 2
    This is incorrect. The .data is hidden from iTunes and putting things in Library/Preferences is a bad idea per the development documentation – Marcus S. Zarra Jul 03 '10 at 15:13
  • Thank you M.Zarra. I hadn't seen this. My answer is correct of course. I don't know which way is the best practice though. – FKDev Jul 05 '10 at 12:32
  • 4
    It's unfortunate that I've been ranked down. My answer is correct. I have an app in the app store that I needed to enable iTunes sharing and I did extensive testing on it. I can, in fact see the directory my app created. I can click on that directory and download it. The directory is in no way hidden. This is on a Windows machine and with system files/hidden files set to visible. My understanding is that this does not work in iTunes on OSX, but it certainly does in Windows. – memmons Jul 07 '10 at 06:37
  • 6
    I think this answer is quite correct. Maybe best choice is to create ones own folder under /Library instead of using /Library/Preferences. Please see also this official Q&A of Apple: http://developer.apple.com/iphone/library/qa/qa2010/qa1699.html – Holtwick Aug 24 '10 at 15:23
  • 3
    Holtwick's suggestion is spot on, read the docs at the link. Long story short (according to Apple), create a /Library/MyAppsPrivateDirectory and store your stuff in there. – Allen Ding Feb 17 '11 at 08:06
  • Thanks Holtwick for the pointer to the official Q&A. Perfect. – William Denniss Jan 23 '13 at 09:46
  • @MarcusS.Zarra I was just revisiting this question. Do you have a link to the docs saying that storing docs in Library/Preferences is contraindicated? Thanks! – memmons Mar 14 '13 at 21:04
  • 1
    There are many things that are advised against that are not in the documentation. Storing things in the preferences directory is one of them. Apple has a history of treating that directory as their own and can/will delete everything in it without notice. That is why the documentation you quoted above suggests creating your own directory under Library. – Marcus S. Zarra Mar 15 '13 at 00:48
2

In the documents directory, create a subdirectory which name starts with a dot. For example:

.data

EDIT: Please stop downgrading this answer !
This answer was correct at the time (remember that it was before the iPad was actually available! And there was a lot of confusion on the matter, we were still hoping for the iPad to appear in the shared devices in the Finder...).
Today (April 2012) it is still working on the Mac but not on Windows (starting a directory name with a dot means nothing in Windows).

Anyway, this Shared Document feature is a mess. Later they fixed it by saying that "Private Documents" should be stored in the Library Folder not in the Documents folder. But remember that developers were already using the Document folder before the iPad came.
Don't blame me for Apple mistakes.
Stack Overflow should have a way to mark an answer as obsolete.
API changes, get fixed, and it renders answers obsolete.

FKDev
  • 2,266
  • 1
  • 20
  • 23
  • this is just the straight unix files that start with a '.' are hidden? so this will still get backed up, i.e. the entire contents of the documents directory gets backed up? – Aran Mulholland May 31 '10 at 23:03
  • 1
    Having tested this on a device, the standard unix hidden dir works fine and is backed up. – Marcus S. Zarra Jul 03 '10 at 15:12