0122 清楚缓存
//start
-(void)clearCashSelf{
MCLog(@"NSHomeDirectory 沙盒路径----%@",NSHomeDirectory());
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除缓存" message: [NSString stringWithFormat:@"清除%.2fM",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除本地缓存" message: [NSString stringWithFormat:@"清除%.2fKB",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.tag = 8899;
[alert show];
}
-(float)fileSizeAtPath:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
if([fileManager fileExistsAtPath:path]){
long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;
// return size/1024.0/1024.0;
return size/1024.0;
}
return 0;
}
-(float)folderSizeAtPath:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
float folderSize;
if ([fileManager fileExistsAtPath:path]) {
NSArray *childerFiles=[fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles) {
NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
folderSize +=[self fileSizeAtPath:absolutePath];
}
return folderSize;
}
return 0;
}
-(void)clearCache:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSArray *childerFiles=[fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles) {
//如有需要,加入条件,过滤掉不想删除的文件
NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
[fileManager removeItemAtPath:absolutePath error:nil];
}
}
[[SDImageCache sharedImageCache] cleanDisk];
}
#
[self clearCashSelf];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachPath = [paths objectAtIndex:0];
[self clearCache:cachPath];
fileSizeM=0;
// [TvDataArray removeAllObjects];
[_TVSatand reloadData];