I am saving Images in NS开发者_开发技巧CachesDirectory in a App. At the end of app execution i would like to clear all temporary cache. Is there a way to force clear all cache on application exit. I do realise the local folder keeps cache for 3 days..but my requirement is to force clear the Cache. Thx
This code should do the trick, just substitute the name of your cache directory...
NSString *cacheDirectoryName = [self getCacheDirectoryName]; NSArray *items = [fileManager directoryContentsAtPath:cacheDirectoryName]; for (NSString *item in items) { NSString *path = [cacheDirectoryName stringByAppendingPathComponent:item]; NSError *error = nil; [fileManager removeItemAtPath:path error:&error]; [error release]; }
Then call the code in your AppDelegate applicationWillTerminate method.
精彩评论