Jordan Smith
Jordan Smith

Reputation: 10378

iOS: Documents directory being 'cleaned'

The Situation

I have an app that stores a core data database in the documents directory. It seems to work well for the most part, except for the fact a few users (of a very large number) are complaining their data just 'disappeared'.

It's a carefully/well coded app, no weird errors or crashes coming from Core Data.

My Suspicion

iOS sometimes shows the word 'cleaning' beneath app icons when storage space is low. This cleans some directories to free up space.

Help!

Could this be the cause? If so, how can I stop this? Any light that can be shed on this would be much appreciated.

Upvotes: 1

Views: 933

Answers (1)

Abhi Beckert
Abhi Beckert

Reputation: 33389

The documents directory is the recommended place to store a core data database and iOS will never "clean up" anything stored there.

Users can manually delete files in the Documents directory, by uninstalling the app or (if you've enabled it in info.plist) browsing their phone from in iTunes.

Most users do not expect their data to be destroyed when they uninstall an app (Macs and PCs would leave the data in place for example), so this is probably what's happening.

You should consider storing a second copy of the data on your server, or on the user's iCloud account. That way it won't be destroyed by an uninstall. If it's your server, then you can justify charging money for this feature (recurring revenue is good right?).

Backups to iTunes and iCloud will both include your database, so you can instruct users to restore to a recent backup to get their data back.

Also double check your code to see how it handles an out of disk space error when attempting to save changes to the database. Depending how you're using Core Data, this could go bad.

These days Core Data in iCloud or some other cloud solution is the best approach.

Upvotes: 1

Related Questions