Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will <Application_Home>/Library/Caches be clear on app update?

In my iPhone app I'm caching the raw data of some compressed files to save loading time. But those files may change in an update.

Will iOS clear /Library/Caches for me when the app is updated or I need to clear it myself?

like image 982
fbafelipe Avatar asked Aug 23 '11 03:08

fbafelipe


People also ask

Is offloading an app the same as clearing its cache?

Is clearing cache the same as offloading? Not exactly, though offloading may help if your phone is slowed down by low storage. Offloading uninstalls an app without deleting any documents and data associated with them.

How do I stop IOS from deleting files?

If you want to prevent apps deleting automatically from your iPhone then you can go to Settings > App Store > and disable Offload Unused Apps to shut off the offload app feature.

What happens when you clear cache on App Store?

Clearing the Google Play Store app cache and data can help eliminate error messages, connection failures, etc. After completing these steps, it's necessary to accept the Google Play Store Terms of Service in order to re-enter the Play Store.


1 Answers

Short:

Will iOS clear /Library/Caches for me when the app is updated No

Is it possible that iOS does clear everything or parts of Application_Home/Library/Caches during an update? Yes

or I need to clear it myself? You need to ensure what you want to be cleared is cleared.

Be prepared for both situations.

How do you know whether your app got updated? See iOS Application Update Test

Long:

Files Saved During Application Updates When a user downloads an application update, iTunes installs the update in a new application directory. It then moves the user’s data files from the old installation over to the new application directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:

  • Application_Home/Documents
  • Application_Home/Library

Although files in other user directories may also be moved over, you should not rely on them being present after an update.

From Apples Documentation: The Application Runtime Environment - Backup and Restore

Application_Home/Library/Caches Use this directory to write any application-specific support files that you want to persist between launches of the application or during application updates. Your application is generally responsible for adding and removing these files. It should also be able to re-create these files as needed because iTunes removes them during a full restoration of the device. In iOS 2.2 and later, the contents of this directory are not backed up by iTunes.

From Apples Documentation: The Application Runtime Environment - The File System (daveoncode)

Here an example of when it does clear the cache during an "update": You install app X V1.0. Lunch it once and the start doing something else. iOS malfunctions and needs to be restored. Developer releases V1.1. You update the app in iTunes on your Mac. You restore your device via iTunes. iTunes installs V1.1. User lunches your app. Your app does not get notified that any of that stuff happened but all files in Application_Home/Library/Cache are gone (iTunes removes them during a full restoration of the device).

Really important information in there: It should also be able to re-create these files as needed. Like Kendall also pointed out it is a cache, so files could be deleted from it by the operating system at any point. So every time you load any file from Application_Home/Library/Caches you have to account for the case that the file isn't there anymore (Kendall touched on this).

NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]; if(![fileManager fileExistsAtPath:[cachePath stringByAppendingPathComponent:@"myfile.zip"]]) {     //create it, copy it from app bundle, download it etc. } //start using it 
like image 127
Thomas Avatar answered Sep 19 '22 20:09

Thomas