iOS计算本地缓存文件大小(M)
2020-04-02 本文已影响0人
烟雨酱南
- (float)getCacheFileSize
{
NSFileManager *fileManager = [NSFileManager defaultManager];
double fileSize = 0.0;
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [fileManager subpathsAtPath:cachPath];
for (NSString *fileName in files)
{
NSString *path = [cachPath stringByAppendingPathComponent:fileName];
if ([fileManager fileExistsAtPath:path])
{
NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:path error:nil];
fileSize += (double)([fileAttributes fileSize]);
}
}
return fileSize/( 1024.0 * 1024.0);
}