I have created an application , where i ll be downloading the images from server and storing it locally on the iPhone's file system. Its happening fine. Now the problem is , i want to clear the locally cached images on iPhone when ever i quit my application.
How do i delete those cached images on iPhone. it's using Secondary memory on iPhone, how do i access it programmatically ?
Thank You in advance. Suse.
Clean them up in your applicationWillTerminate method.
My answer would be as per Kirky Todds, but don't use
applicationWillTerminate
-- it's not a good strategy on iOS4+ with multitasking, because this method often won't get called -- an app will be background, and then can be dumped from memory if other apps are run (or the phone is turned off/restarted), withoutapplicationWillTerminate
getting called. (OR it will be foregrounded again. Either way, your cache doesn't get cleared.)Instead, consider either clearing at startup (
applicationDidFinishLaunching
), or inapplicationWillEnterForeground
. The latter will tend to get called more frequently, because the former is only called on an actual proper app lauch (and not on a resume from being backgrounded).For more info on backgrounding and the events generated, see:
http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/