Programmatically Clear Extra Cache on iPhone

I created an application in which I will download images from the server and store them locally in the iPhone file system. This is going well. Now the problem is that I want to clear the locally cached images on the iPhone when I ever leave the application.

How to delete these cached images on iPhone. it uses Secondary memory on the iPhone, how do I access it programmatically?

Thank you in advance. Suse.

+1
source share
2 answers

Clean them in the applicationWillTerminate method.

- (void)applicationWillTerminate:(UIApplication *)application
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *imagesFiles = [fileManager contentsOfDirectoryAtPath:saveDirectory error:error];
    for (NSString *file in imagesFiles) {
        error = nil;
        [fileManager removeItemAtPath:[saveDirectory stringByAppendingPathComponent:file] error:error];
        /* do error handling here */
    }
}
+3
source

, Kirky Todds, applicationWillTerminate - iOS4 + , - , , ( /), applicationWillTerminate. ( . , .)

(applicationDidFinishLaunching) applicationWillEnterForeground. , ( ).

.

http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/

+4

All Articles