开发者

Clear Absolute Cache on Application close Ipad app

开发者 https://www.devze.com 2022-12-30 03:21 出处:网络
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 d

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号