2

Currently i was saving my application data (Media) to the CacheDirectory i.e

/var/mobile/Applications/BEAFC76C-C450-4A3A-9765-A0385A9580F3/Library/Caches

and things were going fine. But recently i got a bug report that the application data has been deleted. When i searched over it, i got this Apple Doc. According to it, DocumentsDirectory should be the ideal place to store the User/Application data.

Put user data in the /Documents/. User data is any data that cannot be recreated by your app, such as user documents and other user-generated content.

And Cache should not be used to store the User Data that could not be reproduced by the application.

Put data cache files in the /Library/Caches directory. Examples of files you should put in this directory include (but are not limited to) database cache files and downloadable content, such as that used by magazine, newspaper, and map apps. Your app should be able to gracefully handle situations where cached data is deleted by the system to free up disk space.

What should be the ideal place to store it.

EDIT:

I have an application that allows user to store Videos and Photos in the application. For that i used CacheDirectory. But i am getting bug reports that the Data (Videos/Photos) is getting deleted. What conclusion i draw is that the data is being getting delete by the Device itself in order to provide space.

Secondly i also wanna give the iTunes sharing function. So only the particular files has to be stored in the DocumentsDirectory. Some files can never be exposed and some has has to be shared. What should be the ideal way to store the files.

Nikhil Lihla
  • 607
  • 6
  • 21
  • 2
    I'm not sure what you're asking. The document you link gives guidance about what kind of files should be stored where. If you have a specific question about what your data fits into, you'll need to give us some information about what you're storing. – Jesse Rusak Dec 05 '13 at 13:43
  • 4
    Your answer is in your own question. "Put user data in the /Documents/" ... I'm not sure what else you want here. User's videos and photos are user data. – beyerss Dec 05 '13 at 13:53
  • The Caches directory is for stuff that the OS can delete when it wants to, to recover space. You should only use it for data you can re-obtain somehow. Eg, images that have been downloaded and can be (automatically, without user intervention) re-downloaded if need be. – Hot Licks Dec 05 '13 at 13:57
  • 1
    (You seem to have all the information there, but you somehow don't believe it. Admit you screwed up and move on.) – Hot Licks Dec 05 '13 at 13:59
  • @HotLicks Yes! i am screwed up. But i want the proper information how to move on in a right way. – Nikhil Lihla Dec 05 '13 at 14:07
  • @beyerss I had built this app in which user can secure their photos. These secured photos can never be exposed via iTunes Sharing. If i save the photos to /var/mobile/Applications/BEAFC76C-C450-4A3A-9765-A0385A9580F3/Documents directory than these will be excessed through iTunes sharing, which i don't want to happen. So where should i save these pictures? – Nikhil Lihla Dec 05 '13 at 14:15

3 Answers3

4

Use Documents (NSDocumentDirectory) for files you wish to share via iTunes.

Use Application Support (NSApplicationSupportDirectory) for files you wish to hide from the user but still be backed up and never deleted by the OS.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
2

Starting iOS 5, Apple says that it's no longer a good thing to save all kind of files in Documents Directory - if you do that, your app will be rejected for sure because this folder is backed up to iTunes & iCloud, unless otherwise specified.

It says that we should save files into Caches or Tmp Directory - these won't be backed up, but it's not a good thing to do because files from these directories can disappear if low memory happens.

So I think the best think to do is to save the important files that you need all the time in your app into Documents Directory and mark them not to be backed up, like this.

Aura
  • 246
  • 1
  • 10
1

Library/Application Support Folder is the folder you should be using.

This directory doesn't always exist, and thus you may need to create it. You can enable or disable whether you want to backup this data with iTunes or not.

This data is not accessible even if you enable file sharing. Only data that you put in Document directory would be shared with iTunes sharing, so you can still protect your data and get it backed up as well. Apple's documentation

Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31