iOS 5 Library/Caches purge callback - ios

Is it possible for the Caches directory to be purged while my app is running, and if so, will my app be notified in any way that this has occured?
Thanks!

I don't know if it is possible for the cleaning to occur while it is running (though my impression is no). However if you want to detect when the cleaning has occurred you can set a test file into the caches directory and check for it's presence.
File Gone = Cache Purged

No, according to the docs:
On iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running. However, you should be aware that iTunes restore is not necessarily the only condition under which the Caches directory can be erased.

Related

is network cache stays after iOS application is removed and reinstall

I have an iOS application that fetches network resources by using URLRequest with default cachePolicy. I would like to know if:
When the application is deleted from my device, is all cached responses are removed as well? Or do they stay somewhere in the device? (until they are expired)
If yes, if I install the app again in that device, when I launch the app, it will get the cached response stored in iOS device instead of fetching original resources from back-end (if the responses are still valid, of course)?
Below is the behaviour of default Cache Policy explained by Apple:
Thanks.
The caches are stored in a file in your app’s container directory (specifically, Caches/BUNDLE_ID/Cache.db in iOS, or Library/Caches/BUNDLE_ID/Cache.db in macOS, IIRC). When the app goes away, so does the cache, and as far as I’m aware, they are never stored in iCloud backups or anything, so there should be no possibility of them resurfacing.
But be aware that other things can cache responses (e.g. proxy servers on the local network), so if your goal is to completely eliminate any possibility of getting a stale response, you should explicitly disable caching for the request.
If your goal is to have a prewarmed cache, you could distribute a cache file in your app bundle and make a copy of it on first launch before enabling the disk cache, but you are probably better off downloading a ZIP archive and managing files on disk yourself if you are trying to do any sort of offline mode, rather than trying to bend NSURLCache to your will.

does iOS deletes NSTemporaryDirectory files when app is running in the background

Can anybody please help me out if the files of NSTemporaryDirectory gets deleted when app is running in background because every where it is written that files will persist in this directory as long as the app is running but here it is not clear if it is the same behaviour in background also.
Any help is highly appreciated.
If the OS becomes starved on disk space, and your app is in the background, I imagine that the OS would kill your app, (like the OS says it can and will at any time while in the background), and then recover your temp directory space.
No, NSTemporaryDirectory will not get deleted in background. iOS automatically clean temporary directories when needed. So, there is nothing like in background NSTemporaryDirectory get cleared or deleted.

IOS: Data persistence between versions of the app

I cannot find any information on topic: what is happening when I release new version of iOS application on iTunes? Is older version on device completely replaced? Or there is a persistence of Documents folder?
Is it possible to make update to be like a "clean" installation?
When you release an update to your iOS app and the user installs it, the system does not wipe out any data from within the app.
This means that data in a given user's Documents directory, NSUserDefaults, as well as the keychain will persist between app updates.
A couple of important notes, however:
The Caches directory of an app is never reliably persisted, so if you want to make sure data stays safe, don't put it in this directory
Items in the keychain seem to persist even if you completely erase the app and re-install it. I've noticed this in the past, so it may be a good thing to keep in mind
In short, if you want data cleaned out of your app on each update (not sure why you would), you'll have to do so manually.
Your Documents folder will not be cleaned.
If you want to clear it, make sure to do it programmatically in your new release.
The Documents folder is deleted only when the user deletes the app.

iOS - Can saving to Library/Caches/ result in error?

If an app starts saving virtually unlimited images (on demand) to the /Library/Caches directory for caching purpose, what will happen when the storage is full? Will saving to the caches folder result in error? OR If the app is open, can the cache of the open app be purged by iOS automatically? If not, is it the responsibility of the developer to initiate this purging process for the open app? OR Is it guaranteed that an attempt to save an image to /Library/Caches will always be successful regardless of whether the purging takes place or not? (Cached images are cleaned by the app on exit).
Yes, it may result in error. No, it will not be purged by iOS automatically while an app is running. Quote from the docs:
Caches
On iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running
So it's your responsibility to cleanup the caches directory while running. However you would probably meet this error in a very rare cases since iOS will try to remove caches of other apps that are not running.

When does iPad clear library/caches?

In response to Apple's changes in iOS data storage guidelines I recently reconfigured an iPad app to store its documents (50MB+) in the library/caches folder.
During testing in the iOS simulator I didn't see any problems with this cache when I simulated an update (following Brad Larsson's suggestion). I also tried deleting all of the contents of the library/caches folder to make sure that my app could recover.
However, when I released the app upgrade I found that my users complained of problems that were traced back to the iPad partially deleting this cache. It seemed like sub-folder structure was at least partially left intact, but sub-folder contents were deleted.
I've redesigned the app to deal with this situation during an upgrade, but I'm worried about what will happen when the iPad decides to clear the library/caches.
Does anyone have any experience or insight into the time when the iPad would try and delete items in this cache?
Thanks
There is no 100% clear answer to this question, because Apples iOS Data Storage Guidelines are very vague … They don't explain in which cases iOS 5 will delete data inside the cache dir …
In most cases iOS starts to kill files when it's getting low on disc space, but sometimes my app lost data for no good reason. So I had do implement some kind of recovery modus to redownload/-generate files the app needs.
This article is interesting: http://iphoneincubator.com/blog/data-management/local-file-storage-in-ios-5
The documentation states the following:
On iOS 5.0 and later, the system may delete the Caches directory on
rare occasions when the system is very low on disk space. This will
never occur while an app is running. However, you should be aware that
iTunes restore is not necessarily the only condition under which the
Caches directory can be erased.
The part about it never occuring while the app is running is crucial for our app, and is a really good insurance that we won't get unexpected behaviour.

Resources