My app downloads a number of files from my internet server, and caches those in the app, such that they are available when off-line. Recently, a couple of customers have complained that (the data originating from) those files sometimes disappears from the app. After long research, I am now reasonably certain that it is iOS which removes the files when disk space is low. I am trying to find a way to prevent that from happening.
The files are currently located in a subdirectory of Library/Caches, which seems the most appropriate place for these files. Note that there is no need to back-up the files to iTunes or iCloud.
I have searched the internet for ways to prevent this removal, but get conflicting information, and cannot find a clear statement from Apple. The most useful info from Apple itself, is the following:
which says that: "the contents of this directory are not backed up by iTunes or iCloud". It also says that: "In iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space." - which is exactly what I am trying to avoid.
But then the following StackOverflow post: https://stackoverflow.com/a/27309392/908621 says that the removal of files is based on whether they can be restored from iCloud backup. The "NSURLIsExcludedFromBackupKey" property should be set to prevent files from being removed.
So my explicit questions for files that do not need to be backed up, but should also stay on the device under low disk space conditions:
- Is the Library/Caches the correct place for these files - if not, what other location is better?
- Is it required and sufficient to set the "NSURLIsExcludedFromBackupKey" for those files (even though files in Libary/Caches are not backed-up anyways according to Apple)?
- Is it sufficient to set the "NSURLIsExcludedFromBackupKey" on the directory the files are in?
- How can I test all this?