1

I am trying to clear cache in iOS 10. But removeAllCachedResponses is not working. Is removeAllCachedResponses broken in iOS10. As this working in iOS 9.

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
Amon
  • 99
  • 1
  • 9

2 Answers2

1

Is this what you're talking about?

[[NSURLCache sharedURLCache] removeAllCachedResponses];

You can also modify the cache behavior of your requests to selectively cache responses. If you're using AFNetworking by chance, you can use setCacheResponseBlock. E.g. in one project I set it to return nil for all large video and audio files. But allow it to cache smaller image files.

[streamingOperation setCacheResponseBlock:^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) {
    return nil; // Ensures we are not unecessarily caching asset data to Cache.db
}];
Mradul Kumar
  • 347
  • 3
  • 17
-2

If you want to delete file from application directory. There are many ways path of File from Directory, following is one of them.

NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *mainPath    = [myPathList  objectAtIndex:0];

mainPath = [mainPath stringByAppendingPathComponent:DirectoryName];

Now you can delete file at this path the mainPath is Full Path of File.

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL fileExists = [fileManager fileExistsAtPath:mainPath];

if (fileExists)
{
     BOOL success = [fileManager removeItemAtPath:mainPath error:&error];
     if (!success) NSLog(@"Error: %@", [error localizedDescription]);

}
Mradul Kumar
  • 347
  • 3
  • 17