1.首先導(dǎo)入
#include <sys/param.h>
#include <sys/mount.h>
2.實(shí)現(xiàn)方法
//獲取手機(jī)剩余空間
+ (NSString *) freeDiskSpaceInBytes{
struct statfs buf;
long long freespace = -1;
if(statfs("/var", &buf) >= 0){
freespace = (long long)(buf.f_bsize * buf.f_bfree);
}
return [NSString stringWithFormat:@"手機(jī)剩余存儲(chǔ)空間為:%qi MB" ,freespace/1024/1024];
}