//获取RAM并调用处理方法
[self fileSizeToString:[NSProcessInfo processInfo].physicalMemory];
//处理获取内存信息
- (NSString*)fileSizeToString:(unsignedlonglong)fileSize {
NSInteger KB = 1024;
NSIntegerMB = KB*KB;
NSIntegerGB = MB*KB;
if(fileSize < KB) {
return@"<1KB";
}
elseif(fileSize < MB) {
return[NSStringstringWithFormat:@"%.1fKB",((CGFloat)fileSize)/KB];
}
elseif(fileSize < GB) {
return[NSStringstringWithFormat:@"%.1fMB",((CGFloat)fileSize)/MB];
}
else{
return[NSStringstringWithFormat:@"%.1f GB",((CGFloat)fileSize)/GB];
}
}
// 获取当前设备可用内存 ROM
- (NSString*) freeDiskSpaceInBytes{
structstatfsbuf;
longlongfreespace = -1;
if(statfs("/var", &buf) >=0){
freespace = (longlong)(buf.f_bsize* buf.f_bfree);
}
return[NSStringstringWithFormat:@"%qi GB",freespace/1024/1024/1024];
}
// 获取当前设备总内存 ROM
-(NSString*)getTotalMemorySize{
structstatfsbuf;
unsignedlonglongfreeSpace = -1;
if(statfs("/var", &buf) >=0){
freeSpace = (unsignedlonglong)(buf.f_bsize* buf.f_blocks);
}
return[NSStringstringWithFormat:@"%qi GB",freeSpace/1024/1024/1024];
}