In what case will folders and files in the iOS application are deleted?

Hello,


On my customers' iPad, folders and files in the Apps/Library/Caches are automatically deleted. Why does it happen?

Just low storage? If storage is already full, will it be automatically deleted from the old one?

Are there other factors? Is there a setting that can be automatically deleted?

If it were to be deleted by the user's own operation what kind of operation?


iPad model: iPad Air 2

iOS version: iOS 11.4


Please help me figure this problem out.

Thanks!

Post not yet marked as solved Up vote post of kenji1979 Down vote post of kenji1979
2.2k views

Replies

From the video iOS Storage Best Practices:

When a device is low on disk space, iOS can help by clearing caches. Files will never be removed from your caches directory if your app is running, and the operating system will start by clearing caches for apps that haven't been used in a while.


Otherwise, I do not know of any other automatic or user process that clears the caches.

Thank you for your answer.


Does the cache get cleared if the free space falls below what percentage?

Does it happen on only iOS 11?

Does the cache get cleared if the free space falls below what percentage?

I don't think an exact percentage is publicly documented.

Does it happen on only iOS 11?

No, it has been this way since at least iOS 5. The following documents, which are several years old, note that the caches may be cleared by the system: App Backup Best Practices and How do I prevent files from being backed up to iCloud and iTunes?.

Thank you for the replay.

Certainly according to the customer, they don't use iCloud and iTunes for backup and it seems that the app's caches are cleared when the appl is inactive.


If I wan to keep that caches of the Apps/Library/Caches, how can I solve it?

Caches by definition are subject to deletion by the system. From the document I posted:


Your app should be able to gracefully handle situations where cached data is deleted by the system to free up disk space.


So, if you want to guarantee that data is not deleted, you must move it somewhere else. Here's what the documentation recommends:


Support files include files your application downloads or generates and that your application can recreate as needed. The location for storing your application’s support files depends on the current iOS version.


In iOS 5.1 and later, store support files in the <Application_Data>/Library/Application Support directory and add the NSURLIsExcludedFromBackupKey attribute to the corresponding NSURL object using the setResourceValue:forKey:error: method. (If you are using Core Foundation, add the kCFURLIsExcludedFromBackupKey key to your CFURLRef object using the CFURLSetResourcePropertyForKey function.) Applying this attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.