Search code examples
iphoneios5nsdocumentdirectory

What is the best place to store application data in ios?


I think there are many questions related to ios storage guideline. I have found one here. But I want few more clarification on that so:

I have few of my files stored in NSDocumentDirectory.. like My Database file, a Plist file and few audio and video files on temporary basis..

Storing files in ios < 5.0 has no issues.. but while refering http://developer.apple.com/library/ios/#qa/qa1719/_index.html show issues

In ios 5.1 has different method and iso 5.0.1 has different.. and ios 5.0 not allowed files to prevent backup

My questions are:

  1. Should I have to implement both methods by checking ios versions for ios 5.1 and 5.0.1?
  2. Should I have to use Caches directory for my database file and plist file rather than NSDocument directory as there is not option for preventing files to backup on icloud in ios 5.0?
  3. iOS will delete your files from the Caches directory when necessary, So how can I store my database file if I store it in Caches directory. I don't want data loss.

As explained in link:

It is not possible to exclude data from backups on iOS 5.0. If your app must support iOS 5.0, then you will need to store your app data in Caches to avoid that data being backed up. iOS will delete your files from the Caches directory when necessary, so your app will need to degrade gracefully if it's data files are deleted.

I don't want my database and plist file to get delete in any condition.

Any suggestion.


Solution

  • You can use the Documents folder to keep your database and plists in place. Since you don't want the database to be backuped, you would mark it using the file properties. Or did I get you wrong?

    UPDATE:

    Instead of using the deprecated way of marking the files for non-back, just use the provided new ways. Take a look here enter link description here how to do so. The right location is still the Dokuments folder, since the files there won't be deleted.