1.計算APP緩存
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
NSString *filePath = [cachesDir stringByAppendingPathComponent:@"com.XXXXX.HappyShopping"];
NSFileManager * manager=[NSFileManager defaultManager];
cell.cacheLabel.text =[NSString stringWithFormat:@"%0.2fM",[[manager attributesOfItemAtPath:filePath error:nil] fileSize]/1024.f] ;
2.清除緩存[SVProgressHUD showWithStatus:@"正在清除緩存" maskType:SVProgressHUDMaskTypeBlack];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [path objectAtIndex:0];
NSFileManager *fileManager=[NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:cachesDir]) {
NSArray *childerFiles=[fileManager subpathsAtPath:cachesDir];
NSLog(@"%@",childerFiles);
for (NSString *fileName in childerFiles)
{
//如有需要,加入條件,過濾掉不想刪除的文件
NSString *absolutePath=[cachesDir stringByAppendingPathComponent:fileName];
[fileManager removeItemAtPath:absolutePath error:nil];
}
}
[SVProgressHUD showSuccessWithStatus:@"成功清除緩存"];
[self.myTabelView reloadData];