iOS 清理缓存

 1 - (void)clearCaChe
 2 {
 3        NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
 4         NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
 5         for (NSString *p in files) {
 6             NSError *error;
 7             NSString *path = [cachPath stringByAppendingPathComponent:p];
 8             if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
 9                 [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
10             }
11         }
12         [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];
13 }
14 
15 
16 - (void)clearCacheSuccess
17 {
18    //清理成功后要做的操作
19 }
原文地址:https://www.cnblogs.com/zhanghuanan/p/5276386.html