获取app缓存大小

1.禁止手机睡眠

[UIApplication sharedApplication].idleTimerDisabled = YES;

2、获取app缓存大小

//用枚举器遍历 一个文件夹的内容
- (CGFloat)getCachSize {
  //获取自定义缓存大小
  NSUIntegerimageCacheSize = [[SDImageCache sharedImageCache] getSize];
  //1.获取 文件夹枚举器
  NSString*myCachePath = [NSHomeDirectory()   stringByAppendingPathComponent:@"Library/Caches"];
  NSDirectoryEnumerator*enumerator = [[NSFileManagerdefaultManager] enumeratorAtPath:myCachePath];   
 __blockNSUIntegercount =0;
//2.遍历
  for(NSString*fileNameinenumerator) {
      NSString*path = [myCachePath stringByAppendingPathComponent:fileName];
      NSDictionary*fileDict = [[NSFileManagerdefaultManager] attributesOfItemAtPath:path error:nil];      
      count += fileDict.fileSize;
  }
  // 得到是字节  转化为自定义所有缓存大小
  MCGFloat totalSize = ((CGFloat)imageCacheSize+count)/1024/1024;
  return totalSize;
}

你可能感兴趣的:(获取app缓存大小)