如何获取 ios 设备的 存储容量

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-26 10:24   36   0

http://blog.csdn.net/a21064346/article/details/8270216


代码如下:

[csharp] view plain copy
  1. #include <sys/statvfs.h>
  2. double get_disk_capacity ( char * path)
  3. {
  4. struct statvfs sfs;
  5. unsigned long long result = 0;
  6. double disk_capacity = 0;
  7. if ( statvfs ( path, &sfs) != -1 )
  8. {
  9. result = (unsigned long long)sfs.f_frsize * sfs.f_blocks;
  10. if (result > 0)
  11. {
  12. disk_capacity = (double)result/(1024*1024);
  13. }
  14. }
  15. return disk_capacity;
  16. }
  17. - (void)printf {
  18. // Sum the size of the two logical partitions (root + user space)
  19. double total_capacity = get_disk_capacity("/") + get_disk_capacity("/private/var");
  20. printf( "%.2f MB", total_capacity);
  21. }

方法2:

[csharp] view plain copy
  1. NSDictionary *fsAttr = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
  2. float diskSize = [[fsAttr objectForKey:NSFileSystemSize] doubleValue] / 1000000000;
  3. NSLog(@"Disk Size: %0.0f",diskSize);
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP