#include <sys/param.h>
#include <sys/mount.h>
//这段代码示范怎么取得 iPhone 的剩余磁盘空间,还有全部磁盘空间
long long freeSpace() {
struct statfs buf;
long long freespace = –1;
if(statfs("/", &buf) >= 0){
freespace = (long long)buf.f_bsize * buf.f_bfree;
}
return freespace;
}
-(float)getTotalDiskSpaceInBytes {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
statfs([[paths lastObject] cString], &tStats);
float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);
return totalSpace;
}