美文网首页
iOS 清除缓存

iOS 清除缓存

作者: 滴答大 | 来源:发表于2016-10-31 13:44 被阅读47次

1.点击单元格弹出提示


NSString *str = [self countCacheSize];

NSString *casheStr = [NSString stringWithFormat:@"缓存大小为%@,确认清理吗?",str];

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"清理缓存" message:casheStr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

[alertView show];

countCacheSize

- (NSString *)countCacheSize{

long long size = 0;

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];

NSFileManager *fileMamager = [NSFileManager defaultManager];

//获取文件夹下的子路径

NSArray *pathArr = [fileMamager subpathsAtPath:path];

//拼接路径

for (NSString *subPath in pathArr) {

NSString *allPath = [path stringByAppendingPathComponent:subPath];

//计算文件的大小

NSDictionary *fileDic = [fileMamager attributesOfItemAtPath:allPath error:nil];

size += [fileDic fileSize];

}

NSString *cache = [NSString stringWithFormat:@"%.2fM",size/1000.0/1000.0];

return cache;

}

2.代理

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if(buttonIndex ==1){

NSString *filepath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];

NSFileManager *fileManger = [NSFileManager defaultManager];

NSArray *arr = [fileManger subpathsAtPath:filepath];

for (NSString *subPath in arr) {

NSString *pathStr = [filepath stringByAppendingPathComponent:subPath];

[fileManger removeItemAtPath:pathStr error:nil];

//重新创建cache文件夹

[fileManger createDirectoryAtPath:filepath withIntermediateDirectories:YES attributes:nil error:nil];

[_tableView reloadRowsAtIndexPaths: @[[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

}

}

}

相关文章

  • WkWebView 清除缓存 ios8

    WkWebView 清除缓存 ios8iOS8系统NSString *libraryDir = NSSearchP...

  • 清楚WKWebView缓存

    WKWebView清除缓存WKWebView,在iOS9以后提供了缓存管理类WKWebsiteDataStore,...

  • iOS清除UIWebView缓存

    使用iOS的webview会自动进行缓存,在开发的时候要记得清除Cookie和缓存。

  • iOS 清除缓存

    iOS的缓存一般分为两部分,一部分是下载数据产生的缓存,这部分有系统做了缓存,在沙盒里面,还有一部分是图片的缓存,...

  • iOS清除缓存

  • 清除缓存ios

  • iOS清除缓存

    #pragma mark - 第一步,计算缓存文件的大小 //首先获取缓存文件的路径 -(NSString *)g...

  • ios清除缓存

  • iOS 清除缓存

    iOS 清除缓存 我们在使用任何一款APP的时候,无论是苹果的 还是安卓的 都会产生一些缓存 ,我们在使用APP的...

  • iOS 清除缓存

    我们在使用任何一款APP的时候,无论是苹果的 还是安卓的 都会产生一些缓存 ,我们在使用APP的时候 就要定期去清...

网友评论

      本文标题:iOS 清除缓存

      本文链接:https://www.haomeiwen.com/subject/pzhputtx.html